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