2 * Arm PrimeCell PL061 General Purpose IO with additional
3 * Luminary Micro Stellaris bits.
5 * Copyright (c) 2007 CodeSourcery.
6 * Written by Paul Brook
8 * This code is licenced under the GPL.
12 #include "primecell.h"
14 //#define DEBUG_PL061 1
17 #define DPRINTF(fmt, args...) \
18 do { printf("pl061: " fmt , ##args); } while (0)
19 #define BADF(fmt, args...) \
20 do { fprintf(stderr, "pl061: error: " fmt , ##args); exit(1);} while (0)
22 #define DPRINTF(fmt, args...) do {} while(0)
23 #define BADF(fmt, args...) \
24 do { fprintf(stderr, "pl061: error: " fmt , ##args);} while (0)
27 static const uint8_t pl061_id
[12] =
28 { 0x00, 0x00, 0x00, 0x00, 0x61, 0x00, 0x18, 0x01, 0x0d, 0xf0, 0x05, 0xb1 };
56 static void pl061_update(pl061_state
*s
)
63 /* Outputs float high. */
64 /* FIXME: This is board dependent. */
65 out
= (s
->data
& s
->dir
) | ~s
->dir
;
66 changed
= s
->old_data
^ out
;
71 for (i
= 0; i
< 8; i
++) {
73 if ((changed
& mask
) && s
->out
) {
74 DPRINTF("Set output %d = %d\n", i
, (out
& mask
) != 0);
75 qemu_set_irq(s
->out
[i
], (out
& mask
) != 0);
79 /* FIXME: Implement input interrupts. */
82 static uint32_t pl061_read(void *opaque
, target_phys_addr_t offset
)
84 pl061_state
*s
= (pl061_state
*)opaque
;
87 if (offset
>= 0xfd0 && offset
< 0x1000) {
88 return pl061_id
[(offset
- 0xfd0) >> 2];
91 return s
->data
& (offset
>> 2);
94 case 0x400: /* Direction */
96 case 0x404: /* Interrupt sense */
98 case 0x408: /* Interrupt both edges */
100 case 0x40c: /* Interupt event */
102 case 0x410: /* Interrupt mask */
104 case 0x414: /* Raw interrupt status */
106 case 0x418: /* Masked interrupt status */
107 return s
->istate
| s
->im
;
108 case 0x420: /* Alternate function select */
110 case 0x500: /* 2mA drive */
112 case 0x504: /* 4mA drive */
114 case 0x508: /* 8mA drive */
116 case 0x50c: /* Open drain */
118 case 0x510: /* Pull-up */
120 case 0x514: /* Pull-down */
122 case 0x518: /* Slew rate control */
124 case 0x51c: /* Digital enable */
126 case 0x520: /* Lock */
128 case 0x524: /* Commit */
131 cpu_abort (cpu_single_env
, "pl061_read: Bad offset %x\n",
137 static void pl061_write(void *opaque
, target_phys_addr_t offset
,
140 pl061_state
*s
= (pl061_state
*)opaque
;
144 if (offset
< 0x400) {
145 mask
= (offset
>> 2) & s
->dir
;
146 s
->data
= (s
->data
& ~mask
) | (value
& mask
);
151 case 0x400: /* Direction */
154 case 0x404: /* Interrupt sense */
157 case 0x408: /* Interrupt both edges */
160 case 0x40c: /* Interupt event */
163 case 0x410: /* Interrupt mask */
166 case 0x41c: /* Interrupt clear */
169 case 0x420: /* Alternate function select */
171 s
->afsel
= (s
->afsel
& ~mask
) | (value
& mask
);
173 case 0x500: /* 2mA drive */
176 case 0x504: /* 4mA drive */
179 case 0x508: /* 8mA drive */
182 case 0x50c: /* Open drain */
185 case 0x510: /* Pull-up */
188 case 0x514: /* Pull-down */
191 case 0x518: /* Slew rate control */
194 case 0x51c: /* Digital enable */
197 case 0x520: /* Lock */
198 s
->locked
= (value
!= 0xacce551);
200 case 0x524: /* Commit */
205 cpu_abort (cpu_single_env
, "pl061_write: Bad offset %x\n",
211 static void pl061_reset(pl061_state
*s
)
217 static void pl061_set_irq(void * opaque
, int irq
, int level
)
219 pl061_state
*s
= (pl061_state
*)opaque
;
223 if ((s
->dir
& mask
) == 0) {
231 static CPUReadMemoryFunc
*pl061_readfn
[] = {
237 static CPUWriteMemoryFunc
*pl061_writefn
[] = {
243 /* Returns an array of inputs. */
244 qemu_irq
*pl061_init(uint32_t base
, qemu_irq irq
, qemu_irq
**out
)
249 s
= (pl061_state
*)qemu_mallocz(sizeof(pl061_state
));
250 iomemtype
= cpu_register_io_memory(0, pl061_readfn
,
252 cpu_register_physical_memory(base
, 0x00001000, iomemtype
);
259 /* ??? Save/restore. */
260 return qemu_allocate_irqs(pl061_set_irq
, s
, 8);