root / hw / display / tc6393xb.c @ bd2be150
History | View | Annotate | Download (18.1 kB)
1 | 7880febd | pbrook | /*
|
---|---|---|---|
2 | 7880febd | pbrook | * Toshiba TC6393XB I/O Controller.
|
3 | 7880febd | pbrook | * Found in Sharp Zaurus SL-6000 (tosa) or some
|
4 | 7880febd | pbrook | * Toshiba e-Series PDAs.
|
5 | 7880febd | pbrook | *
|
6 | 7880febd | pbrook | * Most features are currently unsupported!!!
|
7 | 7880febd | pbrook | *
|
8 | 7880febd | pbrook | * This code is licensed under the GNU GPL v2.
|
9 | 6b620ca3 | Paolo Bonzini | *
|
10 | 6b620ca3 | Paolo Bonzini | * Contributions after 2012-01-13 are licensed under the terms of the
|
11 | 6b620ca3 | Paolo Bonzini | * GNU GPL, version 2 or (at your option) any later version.
|
12 | 7880febd | pbrook | */
|
13 | 83c9f4ca | Paolo Bonzini | #include "hw/hw.h" |
14 | bd2be150 | Peter Maydell | #include "hw/devices.h" |
15 | 0d09e41a | Paolo Bonzini | #include "hw/block/flash.h" |
16 | 28ecbaee | Paolo Bonzini | #include "ui/console.h" |
17 | 28ecbaee | Paolo Bonzini | #include "ui/pixel_ops.h" |
18 | 9c17d615 | Paolo Bonzini | #include "sysemu/blockdev.h" |
19 | a6569fc5 | balrog | |
20 | a6569fc5 | balrog | #define IRQ_TC6393_NAND 0 |
21 | a6569fc5 | balrog | #define IRQ_TC6393_MMC 1 |
22 | a6569fc5 | balrog | #define IRQ_TC6393_OHCI 2 |
23 | a6569fc5 | balrog | #define IRQ_TC6393_SERIAL 3 |
24 | a6569fc5 | balrog | #define IRQ_TC6393_FB 4 |
25 | a6569fc5 | balrog | |
26 | a6569fc5 | balrog | #define TC6393XB_NR_IRQS 8 |
27 | 88d2c950 | balrog | |
28 | 88d2c950 | balrog | #define TC6393XB_GPIOS 16 |
29 | 88d2c950 | balrog | |
30 | 88d2c950 | balrog | #define SCR_REVID 0x08 /* b Revision ID */ |
31 | 88d2c950 | balrog | #define SCR_ISR 0x50 /* b Interrupt Status */ |
32 | 88d2c950 | balrog | #define SCR_IMR 0x52 /* b Interrupt Mask */ |
33 | 88d2c950 | balrog | #define SCR_IRR 0x54 /* b Interrupt Routing */ |
34 | 88d2c950 | balrog | #define SCR_GPER 0x60 /* w GP Enable */ |
35 | 88d2c950 | balrog | #define SCR_GPI_SR(i) (0x64 + (i)) /* b3 GPI Status */ |
36 | 88d2c950 | balrog | #define SCR_GPI_IMR(i) (0x68 + (i)) /* b3 GPI INT Mask */ |
37 | 88d2c950 | balrog | #define SCR_GPI_EDER(i) (0x6c + (i)) /* b3 GPI Edge Detect Enable */ |
38 | 88d2c950 | balrog | #define SCR_GPI_LIR(i) (0x70 + (i)) /* b3 GPI Level Invert */ |
39 | 88d2c950 | balrog | #define SCR_GPO_DSR(i) (0x78 + (i)) /* b3 GPO Data Set */ |
40 | 88d2c950 | balrog | #define SCR_GPO_DOECR(i) (0x7c + (i)) /* b3 GPO Data OE Control */ |
41 | 88d2c950 | balrog | #define SCR_GP_IARCR(i) (0x80 + (i)) /* b3 GP Internal Active Register Control */ |
42 | 88d2c950 | balrog | #define SCR_GP_IARLCR(i) (0x84 + (i)) /* b3 GP INTERNAL Active Register Level Control */ |
43 | 88d2c950 | balrog | #define SCR_GPI_BCR(i) (0x88 + (i)) /* b3 GPI Buffer Control */ |
44 | 88d2c950 | balrog | #define SCR_GPA_IARCR 0x8c /* w GPa Internal Active Register Control */ |
45 | 88d2c950 | balrog | #define SCR_GPA_IARLCR 0x90 /* w GPa Internal Active Register Level Control */ |
46 | 88d2c950 | balrog | #define SCR_GPA_BCR 0x94 /* w GPa Buffer Control */ |
47 | 88d2c950 | balrog | #define SCR_CCR 0x98 /* w Clock Control */ |
48 | 88d2c950 | balrog | #define SCR_PLL2CR 0x9a /* w PLL2 Control */ |
49 | 88d2c950 | balrog | #define SCR_PLL1CR 0x9c /* l PLL1 Control */ |
50 | 88d2c950 | balrog | #define SCR_DIARCR 0xa0 /* b Device Internal Active Register Control */ |
51 | 88d2c950 | balrog | #define SCR_DBOCR 0xa1 /* b Device Buffer Off Control */ |
52 | 88d2c950 | balrog | #define SCR_FER 0xe0 /* b Function Enable */ |
53 | 88d2c950 | balrog | #define SCR_MCR 0xe4 /* w Mode Control */ |
54 | 88d2c950 | balrog | #define SCR_CONFIG 0xfc /* b Configuration Control */ |
55 | 88d2c950 | balrog | #define SCR_DEBUG 0xff /* b Debug */ |
56 | 88d2c950 | balrog | |
57 | a6569fc5 | balrog | #define NAND_CFG_COMMAND 0x04 /* w Command */ |
58 | a6569fc5 | balrog | #define NAND_CFG_BASE 0x10 /* l Control Base Address */ |
59 | a6569fc5 | balrog | #define NAND_CFG_INTP 0x3d /* b Interrupt Pin */ |
60 | a6569fc5 | balrog | #define NAND_CFG_INTE 0x48 /* b Int Enable */ |
61 | a6569fc5 | balrog | #define NAND_CFG_EC 0x4a /* b Event Control */ |
62 | a6569fc5 | balrog | #define NAND_CFG_ICC 0x4c /* b Internal Clock Control */ |
63 | a6569fc5 | balrog | #define NAND_CFG_ECCC 0x5b /* b ECC Control */ |
64 | a6569fc5 | balrog | #define NAND_CFG_NFTC 0x60 /* b NAND Flash Transaction Control */ |
65 | a6569fc5 | balrog | #define NAND_CFG_NFM 0x61 /* b NAND Flash Monitor */ |
66 | a6569fc5 | balrog | #define NAND_CFG_NFPSC 0x62 /* b NAND Flash Power Supply Control */ |
67 | a6569fc5 | balrog | #define NAND_CFG_NFDC 0x63 /* b NAND Flash Detect Control */ |
68 | a6569fc5 | balrog | |
69 | a6569fc5 | balrog | #define NAND_DATA 0x00 /* l Data */ |
70 | a6569fc5 | balrog | #define NAND_MODE 0x04 /* b Mode */ |
71 | a6569fc5 | balrog | #define NAND_STATUS 0x05 /* b Status */ |
72 | a6569fc5 | balrog | #define NAND_ISR 0x06 /* b Interrupt Status */ |
73 | a6569fc5 | balrog | #define NAND_IMR 0x07 /* b Interrupt Mask */ |
74 | a6569fc5 | balrog | |
75 | a6569fc5 | balrog | #define NAND_MODE_WP 0x80 |
76 | a6569fc5 | balrog | #define NAND_MODE_CE 0x10 |
77 | a6569fc5 | balrog | #define NAND_MODE_ALE 0x02 |
78 | a6569fc5 | balrog | #define NAND_MODE_CLE 0x01 |
79 | a6569fc5 | balrog | #define NAND_MODE_ECC_MASK 0x60 |
80 | a6569fc5 | balrog | #define NAND_MODE_ECC_EN 0x20 |
81 | a6569fc5 | balrog | #define NAND_MODE_ECC_READ 0x40 |
82 | a6569fc5 | balrog | #define NAND_MODE_ECC_RST 0x60 |
83 | a6569fc5 | balrog | |
84 | bc24a225 | Paul Brook | struct TC6393xbState {
|
85 | fe06bd93 | Avi Kivity | MemoryRegion iomem; |
86 | a6569fc5 | balrog | qemu_irq irq; |
87 | a6569fc5 | balrog | qemu_irq *sub_irqs; |
88 | 88d2c950 | balrog | struct {
|
89 | 88d2c950 | balrog | uint8_t ISR; |
90 | 88d2c950 | balrog | uint8_t IMR; |
91 | 88d2c950 | balrog | uint8_t IRR; |
92 | 88d2c950 | balrog | uint16_t GPER; |
93 | 88d2c950 | balrog | uint8_t GPI_SR[3];
|
94 | 88d2c950 | balrog | uint8_t GPI_IMR[3];
|
95 | 88d2c950 | balrog | uint8_t GPI_EDER[3];
|
96 | 88d2c950 | balrog | uint8_t GPI_LIR[3];
|
97 | 88d2c950 | balrog | uint8_t GP_IARCR[3];
|
98 | 88d2c950 | balrog | uint8_t GP_IARLCR[3];
|
99 | 88d2c950 | balrog | uint8_t GPI_BCR[3];
|
100 | 88d2c950 | balrog | uint16_t GPA_IARCR; |
101 | 88d2c950 | balrog | uint16_t GPA_IARLCR; |
102 | 88d2c950 | balrog | uint16_t CCR; |
103 | 88d2c950 | balrog | uint16_t PLL2CR; |
104 | 88d2c950 | balrog | uint32_t PLL1CR; |
105 | 88d2c950 | balrog | uint8_t DIARCR; |
106 | 88d2c950 | balrog | uint8_t DBOCR; |
107 | 88d2c950 | balrog | uint8_t FER; |
108 | 88d2c950 | balrog | uint16_t MCR; |
109 | 88d2c950 | balrog | uint8_t CONFIG; |
110 | 88d2c950 | balrog | uint8_t DEBUG; |
111 | 88d2c950 | balrog | } scr; |
112 | 88d2c950 | balrog | uint32_t gpio_dir; |
113 | 88d2c950 | balrog | uint32_t gpio_level; |
114 | 88d2c950 | balrog | uint32_t prev_level; |
115 | 88d2c950 | balrog | qemu_irq handler[TC6393XB_GPIOS]; |
116 | 88d2c950 | balrog | qemu_irq *gpio_in; |
117 | a6569fc5 | balrog | |
118 | a6569fc5 | balrog | struct {
|
119 | a6569fc5 | balrog | uint8_t mode; |
120 | a6569fc5 | balrog | uint8_t isr; |
121 | a6569fc5 | balrog | uint8_t imr; |
122 | a6569fc5 | balrog | } nand; |
123 | a6569fc5 | balrog | int nand_enable;
|
124 | a6569fc5 | balrog | uint32_t nand_phys; |
125 | d4220389 | Juha Riihimäki | DeviceState *flash; |
126 | bc24a225 | Paul Brook | ECCState ecc; |
127 | 64b40bc5 | balrog | |
128 | c78f7137 | Gerd Hoffmann | QemuConsole *con; |
129 | fe06bd93 | Avi Kivity | MemoryRegion vram; |
130 | 44654490 | pbrook | uint16_t *vram_ptr; |
131 | 64b40bc5 | balrog | uint32_t scr_width, scr_height; /* in pixels */
|
132 | 64b40bc5 | balrog | qemu_irq l3v; |
133 | 64b40bc5 | balrog | unsigned blank : 1, |
134 | 64b40bc5 | balrog | blanked : 1;
|
135 | 88d2c950 | balrog | }; |
136 | 88d2c950 | balrog | |
137 | bc24a225 | Paul Brook | qemu_irq *tc6393xb_gpio_in_get(TC6393xbState *s) |
138 | 88d2c950 | balrog | { |
139 | 88d2c950 | balrog | return s->gpio_in;
|
140 | 88d2c950 | balrog | } |
141 | 88d2c950 | balrog | |
142 | 88d2c950 | balrog | static void tc6393xb_gpio_set(void *opaque, int line, int level) |
143 | 88d2c950 | balrog | { |
144 | bc24a225 | Paul Brook | // TC6393xbState *s = opaque;
|
145 | 88d2c950 | balrog | |
146 | 88d2c950 | balrog | if (line > TC6393XB_GPIOS) {
|
147 | 88d2c950 | balrog | printf("%s: No GPIO pin %i\n", __FUNCTION__, line);
|
148 | 88d2c950 | balrog | return;
|
149 | 88d2c950 | balrog | } |
150 | 88d2c950 | balrog | |
151 | 88d2c950 | balrog | // FIXME: how does the chip reflect the GPIO input level change?
|
152 | 88d2c950 | balrog | } |
153 | 88d2c950 | balrog | |
154 | bc24a225 | Paul Brook | void tc6393xb_gpio_out_set(TC6393xbState *s, int line, |
155 | 88d2c950 | balrog | qemu_irq handler) |
156 | 88d2c950 | balrog | { |
157 | 88d2c950 | balrog | if (line >= TC6393XB_GPIOS) {
|
158 | 88d2c950 | balrog | fprintf(stderr, "TC6393xb: no GPIO pin %d\n", line);
|
159 | 88d2c950 | balrog | return;
|
160 | 88d2c950 | balrog | } |
161 | 88d2c950 | balrog | |
162 | 88d2c950 | balrog | s->handler[line] = handler; |
163 | 88d2c950 | balrog | } |
164 | 88d2c950 | balrog | |
165 | bc24a225 | Paul Brook | static void tc6393xb_gpio_handler_update(TC6393xbState *s) |
166 | 88d2c950 | balrog | { |
167 | 88d2c950 | balrog | uint32_t level, diff; |
168 | 88d2c950 | balrog | int bit;
|
169 | 88d2c950 | balrog | |
170 | 88d2c950 | balrog | level = s->gpio_level & s->gpio_dir; |
171 | 88d2c950 | balrog | |
172 | 88d2c950 | balrog | for (diff = s->prev_level ^ level; diff; diff ^= 1 << bit) { |
173 | 88d2c950 | balrog | bit = ffs(diff) - 1;
|
174 | 88d2c950 | balrog | qemu_set_irq(s->handler[bit], (level >> bit) & 1);
|
175 | 88d2c950 | balrog | } |
176 | 88d2c950 | balrog | |
177 | 88d2c950 | balrog | s->prev_level = level; |
178 | 88d2c950 | balrog | } |
179 | 88d2c950 | balrog | |
180 | bc24a225 | Paul Brook | qemu_irq tc6393xb_l3v_get(TC6393xbState *s) |
181 | 64b40bc5 | balrog | { |
182 | 64b40bc5 | balrog | return s->l3v;
|
183 | 64b40bc5 | balrog | } |
184 | 64b40bc5 | balrog | |
185 | 64b40bc5 | balrog | static void tc6393xb_l3v(void *opaque, int line, int level) |
186 | 64b40bc5 | balrog | { |
187 | bc24a225 | Paul Brook | TC6393xbState *s = opaque; |
188 | 64b40bc5 | balrog | s->blank = !level; |
189 | 64b40bc5 | balrog | fprintf(stderr, "L3V: %d\n", level);
|
190 | 64b40bc5 | balrog | } |
191 | 64b40bc5 | balrog | |
192 | a6569fc5 | balrog | static void tc6393xb_sub_irq(void *opaque, int line, int level) { |
193 | bc24a225 | Paul Brook | TC6393xbState *s = opaque; |
194 | a6569fc5 | balrog | uint8_t isr = s->scr.ISR; |
195 | a6569fc5 | balrog | if (level)
|
196 | a6569fc5 | balrog | isr |= 1 << line;
|
197 | a6569fc5 | balrog | else
|
198 | a6569fc5 | balrog | isr &= ~(1 << line);
|
199 | a6569fc5 | balrog | s->scr.ISR = isr; |
200 | a6569fc5 | balrog | qemu_set_irq(s->irq, isr & s->scr.IMR); |
201 | a6569fc5 | balrog | } |
202 | a6569fc5 | balrog | |
203 | 88d2c950 | balrog | #define SCR_REG_B(N) \
|
204 | 88d2c950 | balrog | case SCR_ ##N: return s->scr.N |
205 | 88d2c950 | balrog | #define SCR_REG_W(N) \
|
206 | 88d2c950 | balrog | case SCR_ ##N: return s->scr.N; \ |
207 | 88d2c950 | balrog | case SCR_ ##N + 1: return s->scr.N >> 8; |
208 | 88d2c950 | balrog | #define SCR_REG_L(N) \
|
209 | 88d2c950 | balrog | case SCR_ ##N: return s->scr.N; \ |
210 | 88d2c950 | balrog | case SCR_ ##N + 1: return s->scr.N >> 8; \ |
211 | 88d2c950 | balrog | case SCR_ ##N + 2: return s->scr.N >> 16; \ |
212 | 88d2c950 | balrog | case SCR_ ##N + 3: return s->scr.N >> 24; |
213 | 88d2c950 | balrog | #define SCR_REG_A(N) \
|
214 | 88d2c950 | balrog | case SCR_ ##N(0): return s->scr.N[0]; \ |
215 | 88d2c950 | balrog | case SCR_ ##N(1): return s->scr.N[1]; \ |
216 | 88d2c950 | balrog | case SCR_ ##N(2): return s->scr.N[2] |
217 | 88d2c950 | balrog | |
218 | a8170e5e | Avi Kivity | static uint32_t tc6393xb_scr_readb(TC6393xbState *s, hwaddr addr)
|
219 | 88d2c950 | balrog | { |
220 | 88d2c950 | balrog | switch (addr) {
|
221 | 88d2c950 | balrog | case SCR_REVID:
|
222 | 88d2c950 | balrog | return 3; |
223 | 88d2c950 | balrog | case SCR_REVID+1: |
224 | 88d2c950 | balrog | return 0; |
225 | 88d2c950 | balrog | SCR_REG_B(ISR); |
226 | 88d2c950 | balrog | SCR_REG_B(IMR); |
227 | 88d2c950 | balrog | SCR_REG_B(IRR); |
228 | 88d2c950 | balrog | SCR_REG_W(GPER); |
229 | 88d2c950 | balrog | SCR_REG_A(GPI_SR); |
230 | 88d2c950 | balrog | SCR_REG_A(GPI_IMR); |
231 | 88d2c950 | balrog | SCR_REG_A(GPI_EDER); |
232 | 88d2c950 | balrog | SCR_REG_A(GPI_LIR); |
233 | 88d2c950 | balrog | case SCR_GPO_DSR(0): |
234 | 88d2c950 | balrog | case SCR_GPO_DSR(1): |
235 | 88d2c950 | balrog | case SCR_GPO_DSR(2): |
236 | 88d2c950 | balrog | return (s->gpio_level >> ((addr - SCR_GPO_DSR(0)) * 8)) & 0xff; |
237 | 88d2c950 | balrog | case SCR_GPO_DOECR(0): |
238 | 88d2c950 | balrog | case SCR_GPO_DOECR(1): |
239 | 88d2c950 | balrog | case SCR_GPO_DOECR(2): |
240 | 88d2c950 | balrog | return (s->gpio_dir >> ((addr - SCR_GPO_DOECR(0)) * 8)) & 0xff; |
241 | 88d2c950 | balrog | SCR_REG_A(GP_IARCR); |
242 | 88d2c950 | balrog | SCR_REG_A(GP_IARLCR); |
243 | 88d2c950 | balrog | SCR_REG_A(GPI_BCR); |
244 | 88d2c950 | balrog | SCR_REG_W(GPA_IARCR); |
245 | 88d2c950 | balrog | SCR_REG_W(GPA_IARLCR); |
246 | 88d2c950 | balrog | SCR_REG_W(CCR); |
247 | 88d2c950 | balrog | SCR_REG_W(PLL2CR); |
248 | 88d2c950 | balrog | SCR_REG_L(PLL1CR); |
249 | 88d2c950 | balrog | SCR_REG_B(DIARCR); |
250 | 88d2c950 | balrog | SCR_REG_B(DBOCR); |
251 | 88d2c950 | balrog | SCR_REG_B(FER); |
252 | 88d2c950 | balrog | SCR_REG_W(MCR); |
253 | 88d2c950 | balrog | SCR_REG_B(CONFIG); |
254 | 88d2c950 | balrog | SCR_REG_B(DEBUG); |
255 | 88d2c950 | balrog | } |
256 | a6569fc5 | balrog | fprintf(stderr, "tc6393xb_scr: unhandled read at %08x\n", (uint32_t) addr);
|
257 | 88d2c950 | balrog | return 0; |
258 | 88d2c950 | balrog | } |
259 | 88d2c950 | balrog | #undef SCR_REG_B
|
260 | 88d2c950 | balrog | #undef SCR_REG_W
|
261 | 88d2c950 | balrog | #undef SCR_REG_L
|
262 | 88d2c950 | balrog | #undef SCR_REG_A
|
263 | 88d2c950 | balrog | |
264 | 88d2c950 | balrog | #define SCR_REG_B(N) \
|
265 | a6569fc5 | balrog | case SCR_ ##N: s->scr.N = value; return; |
266 | 88d2c950 | balrog | #define SCR_REG_W(N) \
|
267 | a6569fc5 | balrog | case SCR_ ##N: s->scr.N = (s->scr.N & ~0xff) | (value & 0xff); return; \ |
268 | a6569fc5 | balrog | case SCR_ ##N + 1: s->scr.N = (s->scr.N & 0xff) | (value << 8); return |
269 | 88d2c950 | balrog | #define SCR_REG_L(N) \
|
270 | a6569fc5 | balrog | case SCR_ ##N: s->scr.N = (s->scr.N & ~0xff) | (value & 0xff); return; \ |
271 | a6569fc5 | balrog | case SCR_ ##N + 1: s->scr.N = (s->scr.N & ~(0xff << 8)) | (value & (0xff << 8)); return; \ |
272 | a6569fc5 | balrog | case SCR_ ##N + 2: s->scr.N = (s->scr.N & ~(0xff << 16)) | (value & (0xff << 16)); return; \ |
273 | a6569fc5 | balrog | case SCR_ ##N + 3: s->scr.N = (s->scr.N & ~(0xff << 24)) | (value & (0xff << 24)); return; |
274 | 88d2c950 | balrog | #define SCR_REG_A(N) \
|
275 | a6569fc5 | balrog | case SCR_ ##N(0): s->scr.N[0] = value; return; \ |
276 | a6569fc5 | balrog | case SCR_ ##N(1): s->scr.N[1] = value; return; \ |
277 | a6569fc5 | balrog | case SCR_ ##N(2): s->scr.N[2] = value; return |
278 | 88d2c950 | balrog | |
279 | a8170e5e | Avi Kivity | static void tc6393xb_scr_writeb(TC6393xbState *s, hwaddr addr, uint32_t value) |
280 | 88d2c950 | balrog | { |
281 | 88d2c950 | balrog | switch (addr) {
|
282 | 88d2c950 | balrog | SCR_REG_B(ISR); |
283 | 88d2c950 | balrog | SCR_REG_B(IMR); |
284 | 88d2c950 | balrog | SCR_REG_B(IRR); |
285 | 88d2c950 | balrog | SCR_REG_W(GPER); |
286 | 88d2c950 | balrog | SCR_REG_A(GPI_SR); |
287 | 88d2c950 | balrog | SCR_REG_A(GPI_IMR); |
288 | 88d2c950 | balrog | SCR_REG_A(GPI_EDER); |
289 | 88d2c950 | balrog | SCR_REG_A(GPI_LIR); |
290 | 88d2c950 | balrog | case SCR_GPO_DSR(0): |
291 | 88d2c950 | balrog | case SCR_GPO_DSR(1): |
292 | 88d2c950 | balrog | case SCR_GPO_DSR(2): |
293 | 88d2c950 | balrog | s->gpio_level = (s->gpio_level & ~(0xff << ((addr - SCR_GPO_DSR(0))*8))) | ((value & 0xff) << ((addr - SCR_GPO_DSR(0))*8)); |
294 | 88d2c950 | balrog | tc6393xb_gpio_handler_update(s); |
295 | a6569fc5 | balrog | return;
|
296 | 88d2c950 | balrog | case SCR_GPO_DOECR(0): |
297 | 88d2c950 | balrog | case SCR_GPO_DOECR(1): |
298 | 88d2c950 | balrog | case SCR_GPO_DOECR(2): |
299 | 88d2c950 | balrog | s->gpio_dir = (s->gpio_dir & ~(0xff << ((addr - SCR_GPO_DOECR(0))*8))) | ((value & 0xff) << ((addr - SCR_GPO_DOECR(0))*8)); |
300 | 88d2c950 | balrog | tc6393xb_gpio_handler_update(s); |
301 | a6569fc5 | balrog | return;
|
302 | 88d2c950 | balrog | SCR_REG_A(GP_IARCR); |
303 | 88d2c950 | balrog | SCR_REG_A(GP_IARLCR); |
304 | 88d2c950 | balrog | SCR_REG_A(GPI_BCR); |
305 | 88d2c950 | balrog | SCR_REG_W(GPA_IARCR); |
306 | 88d2c950 | balrog | SCR_REG_W(GPA_IARLCR); |
307 | 88d2c950 | balrog | SCR_REG_W(CCR); |
308 | 88d2c950 | balrog | SCR_REG_W(PLL2CR); |
309 | 88d2c950 | balrog | SCR_REG_L(PLL1CR); |
310 | 88d2c950 | balrog | SCR_REG_B(DIARCR); |
311 | 88d2c950 | balrog | SCR_REG_B(DBOCR); |
312 | 88d2c950 | balrog | SCR_REG_B(FER); |
313 | 88d2c950 | balrog | SCR_REG_W(MCR); |
314 | 88d2c950 | balrog | SCR_REG_B(CONFIG); |
315 | 88d2c950 | balrog | SCR_REG_B(DEBUG); |
316 | 88d2c950 | balrog | } |
317 | a6569fc5 | balrog | fprintf(stderr, "tc6393xb_scr: unhandled write at %08x: %02x\n",
|
318 | a6569fc5 | balrog | (uint32_t) addr, value & 0xff);
|
319 | 88d2c950 | balrog | } |
320 | 88d2c950 | balrog | #undef SCR_REG_B
|
321 | 88d2c950 | balrog | #undef SCR_REG_W
|
322 | 88d2c950 | balrog | #undef SCR_REG_L
|
323 | 88d2c950 | balrog | #undef SCR_REG_A
|
324 | 88d2c950 | balrog | |
325 | bc24a225 | Paul Brook | static void tc6393xb_nand_irq(TC6393xbState *s) { |
326 | a6569fc5 | balrog | qemu_set_irq(s->sub_irqs[IRQ_TC6393_NAND], |
327 | a6569fc5 | balrog | (s->nand.imr & 0x80) && (s->nand.imr & s->nand.isr));
|
328 | a6569fc5 | balrog | } |
329 | a6569fc5 | balrog | |
330 | a8170e5e | Avi Kivity | static uint32_t tc6393xb_nand_cfg_readb(TC6393xbState *s, hwaddr addr) {
|
331 | a6569fc5 | balrog | switch (addr) {
|
332 | a6569fc5 | balrog | case NAND_CFG_COMMAND:
|
333 | a6569fc5 | balrog | return s->nand_enable ? 2 : 0; |
334 | a6569fc5 | balrog | case NAND_CFG_BASE:
|
335 | a6569fc5 | balrog | case NAND_CFG_BASE + 1: |
336 | a6569fc5 | balrog | case NAND_CFG_BASE + 2: |
337 | a6569fc5 | balrog | case NAND_CFG_BASE + 3: |
338 | a6569fc5 | balrog | return s->nand_phys >> (addr - NAND_CFG_BASE);
|
339 | a6569fc5 | balrog | } |
340 | a6569fc5 | balrog | fprintf(stderr, "tc6393xb_nand_cfg: unhandled read at %08x\n", (uint32_t) addr);
|
341 | a6569fc5 | balrog | return 0; |
342 | a6569fc5 | balrog | } |
343 | a8170e5e | Avi Kivity | static void tc6393xb_nand_cfg_writeb(TC6393xbState *s, hwaddr addr, uint32_t value) { |
344 | a6569fc5 | balrog | switch (addr) {
|
345 | a6569fc5 | balrog | case NAND_CFG_COMMAND:
|
346 | a6569fc5 | balrog | s->nand_enable = (value & 0x2);
|
347 | a6569fc5 | balrog | return;
|
348 | a6569fc5 | balrog | case NAND_CFG_BASE:
|
349 | a6569fc5 | balrog | case NAND_CFG_BASE + 1: |
350 | a6569fc5 | balrog | case NAND_CFG_BASE + 2: |
351 | a6569fc5 | balrog | case NAND_CFG_BASE + 3: |
352 | a6569fc5 | balrog | s->nand_phys &= ~(0xff << ((addr - NAND_CFG_BASE) * 8)); |
353 | a6569fc5 | balrog | s->nand_phys |= (value & 0xff) << ((addr - NAND_CFG_BASE) * 8); |
354 | a6569fc5 | balrog | return;
|
355 | a6569fc5 | balrog | } |
356 | a6569fc5 | balrog | fprintf(stderr, "tc6393xb_nand_cfg: unhandled write at %08x: %02x\n",
|
357 | a6569fc5 | balrog | (uint32_t) addr, value & 0xff);
|
358 | a6569fc5 | balrog | } |
359 | a6569fc5 | balrog | |
360 | a8170e5e | Avi Kivity | static uint32_t tc6393xb_nand_readb(TC6393xbState *s, hwaddr addr) {
|
361 | a6569fc5 | balrog | switch (addr) {
|
362 | a6569fc5 | balrog | case NAND_DATA + 0: |
363 | a6569fc5 | balrog | case NAND_DATA + 1: |
364 | a6569fc5 | balrog | case NAND_DATA + 2: |
365 | a6569fc5 | balrog | case NAND_DATA + 3: |
366 | a6569fc5 | balrog | return nand_getio(s->flash);
|
367 | a6569fc5 | balrog | case NAND_MODE:
|
368 | a6569fc5 | balrog | return s->nand.mode;
|
369 | a6569fc5 | balrog | case NAND_STATUS:
|
370 | a6569fc5 | balrog | return 0x14; |
371 | a6569fc5 | balrog | case NAND_ISR:
|
372 | a6569fc5 | balrog | return s->nand.isr;
|
373 | a6569fc5 | balrog | case NAND_IMR:
|
374 | a6569fc5 | balrog | return s->nand.imr;
|
375 | a6569fc5 | balrog | } |
376 | a6569fc5 | balrog | fprintf(stderr, "tc6393xb_nand: unhandled read at %08x\n", (uint32_t) addr);
|
377 | a6569fc5 | balrog | return 0; |
378 | a6569fc5 | balrog | } |
379 | a8170e5e | Avi Kivity | static void tc6393xb_nand_writeb(TC6393xbState *s, hwaddr addr, uint32_t value) { |
380 | a6569fc5 | balrog | // fprintf(stderr, "tc6393xb_nand: write at %08x: %02x\n",
|
381 | a6569fc5 | balrog | // (uint32_t) addr, value & 0xff);
|
382 | a6569fc5 | balrog | switch (addr) {
|
383 | a6569fc5 | balrog | case NAND_DATA + 0: |
384 | a6569fc5 | balrog | case NAND_DATA + 1: |
385 | a6569fc5 | balrog | case NAND_DATA + 2: |
386 | a6569fc5 | balrog | case NAND_DATA + 3: |
387 | a6569fc5 | balrog | nand_setio(s->flash, value); |
388 | f23c1b2a | Dmitry Eremin-Solenikov | s->nand.isr |= 1;
|
389 | a6569fc5 | balrog | tc6393xb_nand_irq(s); |
390 | a6569fc5 | balrog | return;
|
391 | a6569fc5 | balrog | case NAND_MODE:
|
392 | a6569fc5 | balrog | s->nand.mode = value; |
393 | a6569fc5 | balrog | nand_setpins(s->flash, |
394 | a6569fc5 | balrog | value & NAND_MODE_CLE, |
395 | a6569fc5 | balrog | value & NAND_MODE_ALE, |
396 | a6569fc5 | balrog | !(value & NAND_MODE_CE), |
397 | a6569fc5 | balrog | value & NAND_MODE_WP, |
398 | a6569fc5 | balrog | 0); // FIXME: gnd |
399 | a6569fc5 | balrog | switch (value & NAND_MODE_ECC_MASK) {
|
400 | a6569fc5 | balrog | case NAND_MODE_ECC_RST:
|
401 | a6569fc5 | balrog | ecc_reset(&s->ecc); |
402 | a6569fc5 | balrog | break;
|
403 | a6569fc5 | balrog | case NAND_MODE_ECC_READ:
|
404 | a6569fc5 | balrog | // FIXME
|
405 | a6569fc5 | balrog | break;
|
406 | a6569fc5 | balrog | case NAND_MODE_ECC_EN:
|
407 | a6569fc5 | balrog | ecc_reset(&s->ecc); |
408 | a6569fc5 | balrog | } |
409 | a6569fc5 | balrog | return;
|
410 | a6569fc5 | balrog | case NAND_ISR:
|
411 | a6569fc5 | balrog | s->nand.isr = value; |
412 | a6569fc5 | balrog | tc6393xb_nand_irq(s); |
413 | a6569fc5 | balrog | return;
|
414 | a6569fc5 | balrog | case NAND_IMR:
|
415 | a6569fc5 | balrog | s->nand.imr = value; |
416 | a6569fc5 | balrog | tc6393xb_nand_irq(s); |
417 | a6569fc5 | balrog | return;
|
418 | a6569fc5 | balrog | } |
419 | a6569fc5 | balrog | fprintf(stderr, "tc6393xb_nand: unhandled write at %08x: %02x\n",
|
420 | a6569fc5 | balrog | (uint32_t) addr, value & 0xff);
|
421 | a6569fc5 | balrog | } |
422 | a6569fc5 | balrog | |
423 | 64b40bc5 | balrog | #define BITS 8 |
424 | 47b43a1f | Paolo Bonzini | #include "tc6393xb_template.h" |
425 | 64b40bc5 | balrog | #define BITS 15 |
426 | 47b43a1f | Paolo Bonzini | #include "tc6393xb_template.h" |
427 | 64b40bc5 | balrog | #define BITS 16 |
428 | 47b43a1f | Paolo Bonzini | #include "tc6393xb_template.h" |
429 | 64b40bc5 | balrog | #define BITS 24 |
430 | 47b43a1f | Paolo Bonzini | #include "tc6393xb_template.h" |
431 | 64b40bc5 | balrog | #define BITS 32 |
432 | 47b43a1f | Paolo Bonzini | #include "tc6393xb_template.h" |
433 | 64b40bc5 | balrog | |
434 | bc24a225 | Paul Brook | static void tc6393xb_draw_graphic(TC6393xbState *s, int full_update) |
435 | 64b40bc5 | balrog | { |
436 | c78f7137 | Gerd Hoffmann | DisplaySurface *surface = qemu_console_surface(s->con); |
437 | c78f7137 | Gerd Hoffmann | |
438 | c78f7137 | Gerd Hoffmann | switch (surface_bits_per_pixel(surface)) {
|
439 | 64b40bc5 | balrog | case 8: |
440 | 64b40bc5 | balrog | tc6393xb_draw_graphic8(s); |
441 | 64b40bc5 | balrog | break;
|
442 | 64b40bc5 | balrog | case 15: |
443 | 64b40bc5 | balrog | tc6393xb_draw_graphic15(s); |
444 | 64b40bc5 | balrog | break;
|
445 | 64b40bc5 | balrog | case 16: |
446 | 64b40bc5 | balrog | tc6393xb_draw_graphic16(s); |
447 | 64b40bc5 | balrog | break;
|
448 | 64b40bc5 | balrog | case 24: |
449 | 64b40bc5 | balrog | tc6393xb_draw_graphic24(s); |
450 | 64b40bc5 | balrog | break;
|
451 | 64b40bc5 | balrog | case 32: |
452 | 64b40bc5 | balrog | tc6393xb_draw_graphic32(s); |
453 | 64b40bc5 | balrog | break;
|
454 | 64b40bc5 | balrog | default:
|
455 | c78f7137 | Gerd Hoffmann | printf("tc6393xb: unknown depth %d\n",
|
456 | c78f7137 | Gerd Hoffmann | surface_bits_per_pixel(surface)); |
457 | 64b40bc5 | balrog | return;
|
458 | 64b40bc5 | balrog | } |
459 | 64b40bc5 | balrog | |
460 | c78f7137 | Gerd Hoffmann | dpy_gfx_update(s->con, 0, 0, s->scr_width, s->scr_height); |
461 | 64b40bc5 | balrog | } |
462 | 64b40bc5 | balrog | |
463 | bc24a225 | Paul Brook | static void tc6393xb_draw_blank(TC6393xbState *s, int full_update) |
464 | 64b40bc5 | balrog | { |
465 | c78f7137 | Gerd Hoffmann | DisplaySurface *surface = qemu_console_surface(s->con); |
466 | 64b40bc5 | balrog | int i, w;
|
467 | 64b40bc5 | balrog | uint8_t *d; |
468 | 64b40bc5 | balrog | |
469 | 64b40bc5 | balrog | if (!full_update)
|
470 | 64b40bc5 | balrog | return;
|
471 | 64b40bc5 | balrog | |
472 | c78f7137 | Gerd Hoffmann | w = s->scr_width * surface_bytes_per_pixel(surface); |
473 | c78f7137 | Gerd Hoffmann | d = surface_data(surface); |
474 | 64b40bc5 | balrog | for(i = 0; i < s->scr_height; i++) { |
475 | 64b40bc5 | balrog | memset(d, 0, w);
|
476 | c78f7137 | Gerd Hoffmann | d += surface_stride(surface); |
477 | 64b40bc5 | balrog | } |
478 | 64b40bc5 | balrog | |
479 | c78f7137 | Gerd Hoffmann | dpy_gfx_update(s->con, 0, 0, s->scr_width, s->scr_height); |
480 | 64b40bc5 | balrog | } |
481 | 64b40bc5 | balrog | |
482 | 64b40bc5 | balrog | static void tc6393xb_update_display(void *opaque) |
483 | 64b40bc5 | balrog | { |
484 | bc24a225 | Paul Brook | TC6393xbState *s = opaque; |
485 | c78f7137 | Gerd Hoffmann | DisplaySurface *surface = qemu_console_surface(s->con); |
486 | 64b40bc5 | balrog | int full_update;
|
487 | 64b40bc5 | balrog | |
488 | 64b40bc5 | balrog | if (s->scr_width == 0 || s->scr_height == 0) |
489 | 64b40bc5 | balrog | return;
|
490 | 64b40bc5 | balrog | |
491 | 64b40bc5 | balrog | full_update = 0;
|
492 | 64b40bc5 | balrog | if (s->blanked != s->blank) {
|
493 | 64b40bc5 | balrog | s->blanked = s->blank; |
494 | 64b40bc5 | balrog | full_update = 1;
|
495 | 64b40bc5 | balrog | } |
496 | c78f7137 | Gerd Hoffmann | if (s->scr_width != surface_width(surface) ||
|
497 | c78f7137 | Gerd Hoffmann | s->scr_height != surface_height(surface)) { |
498 | c78f7137 | Gerd Hoffmann | qemu_console_resize(s->con, s->scr_width, s->scr_height); |
499 | 64b40bc5 | balrog | full_update = 1;
|
500 | 64b40bc5 | balrog | } |
501 | 64b40bc5 | balrog | if (s->blanked)
|
502 | 64b40bc5 | balrog | tc6393xb_draw_blank(s, full_update); |
503 | 64b40bc5 | balrog | else
|
504 | 64b40bc5 | balrog | tc6393xb_draw_graphic(s, full_update); |
505 | 64b40bc5 | balrog | } |
506 | 64b40bc5 | balrog | |
507 | 64b40bc5 | balrog | |
508 | a8170e5e | Avi Kivity | static uint64_t tc6393xb_readb(void *opaque, hwaddr addr, |
509 | fe06bd93 | Avi Kivity | unsigned size)
|
510 | fe06bd93 | Avi Kivity | { |
511 | bc24a225 | Paul Brook | TC6393xbState *s = opaque; |
512 | a6569fc5 | balrog | |
513 | a6569fc5 | balrog | switch (addr >> 8) { |
514 | a6569fc5 | balrog | case 0: |
515 | a6569fc5 | balrog | return tc6393xb_scr_readb(s, addr & 0xff); |
516 | a6569fc5 | balrog | case 1: |
517 | a6569fc5 | balrog | return tc6393xb_nand_cfg_readb(s, addr & 0xff); |
518 | a6569fc5 | balrog | }; |
519 | a6569fc5 | balrog | |
520 | a6569fc5 | balrog | if ((addr &~0xff) == s->nand_phys && s->nand_enable) { |
521 | a6569fc5 | balrog | // return tc6393xb_nand_readb(s, addr & 0xff);
|
522 | a6569fc5 | balrog | uint8_t d = tc6393xb_nand_readb(s, addr & 0xff);
|
523 | a6569fc5 | balrog | // fprintf(stderr, "tc6393xb_nand: read at %08x: %02hhx\n", (uint32_t) addr, d);
|
524 | a6569fc5 | balrog | return d;
|
525 | a6569fc5 | balrog | } |
526 | a6569fc5 | balrog | |
527 | a6569fc5 | balrog | // fprintf(stderr, "tc6393xb: unhandled read at %08x\n", (uint32_t) addr);
|
528 | a6569fc5 | balrog | return 0; |
529 | a6569fc5 | balrog | } |
530 | a6569fc5 | balrog | |
531 | a8170e5e | Avi Kivity | static void tc6393xb_writeb(void *opaque, hwaddr addr, |
532 | fe06bd93 | Avi Kivity | uint64_t value, unsigned size) {
|
533 | bc24a225 | Paul Brook | TC6393xbState *s = opaque; |
534 | a6569fc5 | balrog | |
535 | a6569fc5 | balrog | switch (addr >> 8) { |
536 | a6569fc5 | balrog | case 0: |
537 | a6569fc5 | balrog | tc6393xb_scr_writeb(s, addr & 0xff, value);
|
538 | a6569fc5 | balrog | return;
|
539 | a6569fc5 | balrog | case 1: |
540 | a6569fc5 | balrog | tc6393xb_nand_cfg_writeb(s, addr & 0xff, value);
|
541 | a6569fc5 | balrog | return;
|
542 | a6569fc5 | balrog | }; |
543 | a6569fc5 | balrog | |
544 | a6569fc5 | balrog | if ((addr &~0xff) == s->nand_phys && s->nand_enable) |
545 | a6569fc5 | balrog | tc6393xb_nand_writeb(s, addr & 0xff, value);
|
546 | a6569fc5 | balrog | else
|
547 | a6569fc5 | balrog | fprintf(stderr, "tc6393xb: unhandled write at %08x: %02x\n",
|
548 | fe06bd93 | Avi Kivity | (uint32_t) addr, (int)value & 0xff); |
549 | 88d2c950 | balrog | } |
550 | 88d2c950 | balrog | |
551 | fe06bd93 | Avi Kivity | TC6393xbState *tc6393xb_init(MemoryRegion *sysmem, uint32_t base, qemu_irq irq) |
552 | 88d2c950 | balrog | { |
553 | bc24a225 | Paul Brook | TC6393xbState *s; |
554 | 522f253c | Peter Maydell | DriveInfo *nand; |
555 | fe06bd93 | Avi Kivity | static const MemoryRegionOps tc6393xb_ops = { |
556 | fe06bd93 | Avi Kivity | .read = tc6393xb_readb, |
557 | fe06bd93 | Avi Kivity | .write = tc6393xb_writeb, |
558 | fe06bd93 | Avi Kivity | .endianness = DEVICE_NATIVE_ENDIAN, |
559 | fe06bd93 | Avi Kivity | .impl = { |
560 | fe06bd93 | Avi Kivity | .min_access_size = 1,
|
561 | fe06bd93 | Avi Kivity | .max_access_size = 1,
|
562 | fe06bd93 | Avi Kivity | }, |
563 | 88d2c950 | balrog | }; |
564 | 88d2c950 | balrog | |
565 | 7267c094 | Anthony Liguori | s = (TC6393xbState *) g_malloc0(sizeof(TC6393xbState));
|
566 | a6569fc5 | balrog | s->irq = irq; |
567 | 88d2c950 | balrog | s->gpio_in = qemu_allocate_irqs(tc6393xb_gpio_set, s, TC6393XB_GPIOS); |
568 | 88d2c950 | balrog | |
569 | 64b40bc5 | balrog | s->l3v = *qemu_allocate_irqs(tc6393xb_l3v, s, 1);
|
570 | 64b40bc5 | balrog | s->blanked = 1;
|
571 | 64b40bc5 | balrog | |
572 | a6569fc5 | balrog | s->sub_irqs = qemu_allocate_irqs(tc6393xb_sub_irq, s, TC6393XB_NR_IRQS); |
573 | a6569fc5 | balrog | |
574 | 522f253c | Peter Maydell | nand = drive_get(IF_MTD, 0, 0); |
575 | 522f253c | Peter Maydell | s->flash = nand_init(nand ? nand->bdrv : NULL, NAND_MFR_TOSHIBA, 0x76); |
576 | a6569fc5 | balrog | |
577 | fe06bd93 | Avi Kivity | memory_region_init_io(&s->iomem, &tc6393xb_ops, s, "tc6393xb", 0x10000); |
578 | fe06bd93 | Avi Kivity | memory_region_add_subregion(sysmem, base, &s->iomem); |
579 | 64b40bc5 | balrog | |
580 | c5705a77 | Avi Kivity | memory_region_init_ram(&s->vram, "tc6393xb.vram", 0x100000); |
581 | c5705a77 | Avi Kivity | vmstate_register_ram_global(&s->vram); |
582 | fe06bd93 | Avi Kivity | s->vram_ptr = memory_region_get_ram_ptr(&s->vram); |
583 | fe06bd93 | Avi Kivity | memory_region_add_subregion(sysmem, base + 0x100000, &s->vram);
|
584 | 3023f332 | aliguori | s->scr_width = 480;
|
585 | 3023f332 | aliguori | s->scr_height = 640;
|
586 | c78f7137 | Gerd Hoffmann | s->con = graphic_console_init(tc6393xb_update_display, |
587 | 3023f332 | aliguori | NULL, /* invalidate */ |
588 | 3023f332 | aliguori | NULL, /* screen_dump */ |
589 | 3023f332 | aliguori | NULL, /* text_update */ |
590 | 3023f332 | aliguori | s); |
591 | 88d2c950 | balrog | |
592 | 88d2c950 | balrog | return s;
|
593 | 88d2c950 | balrog | } |