2 * Arm PrimeCell PL050 Keyboard / Mouse Interface
4 * Copyright (c) 2006-2007 CodeSourcery.
5 * Written by Paul Brook
7 * This code is licenced under the GPL.
24 #define PL050_TXEMPTY (1 << 6)
25 #define PL050_TXBUSY (1 << 5)
26 #define PL050_RXFULL (1 << 4)
27 #define PL050_RXBUSY (1 << 3)
28 #define PL050_RXPARITY (1 << 2)
29 #define PL050_KMIC (1 << 1)
30 #define PL050_KMID (1 << 0)
32 static const unsigned char pl050_id
[] =
33 { 0x50, 0x10, 0x04, 0x00, 0x0d, 0xf0, 0x05, 0xb1 };
35 static void pl050_update(void *opaque
, int level
)
37 pl050_state
*s
= (pl050_state
*)opaque
;
41 raise
= (s
->pending
&& (s
->cr
& 0x10) != 0)
42 || (s
->cr
& 0x08) != 0;
43 qemu_set_irq(s
->irq
, raise
);
46 static uint32_t pl050_read(void *opaque
, target_phys_addr_t offset
)
48 pl050_state
*s
= (pl050_state
*)opaque
;
49 if (offset
>= 0xfe0 && offset
< 0x1000)
50 return pl050_id
[(offset
- 0xfe0) >> 2];
52 switch (offset
>> 2) {
61 val
= val
^ (val
>> 4);
62 val
= val
^ (val
>> 2);
63 val
= (val
^ (val
>> 1)) & 1;
67 stat
|= PL050_RXPARITY
;
75 s
->last
= ps2_read_data(s
->dev
);
77 case 3: /* KMICLKDIV */
80 return s
->pending
| 2;
82 hw_error("pl050_read: Bad offset %x\n", (int)offset
);
87 static void pl050_write(void *opaque
, target_phys_addr_t offset
,
90 pl050_state
*s
= (pl050_state
*)opaque
;
91 switch (offset
>> 2) {
94 pl050_update(s
, s
->pending
);
95 /* ??? Need to implement the enable/disable bit. */
98 /* ??? This should toggle the TX interrupt line. */
99 /* ??? This means kbd/mouse can block each other. */
101 ps2_write_mouse(s
->dev
, value
);
103 ps2_write_keyboard(s
->dev
, value
);
106 case 3: /* KMICLKDIV */
110 hw_error("pl050_write: Bad offset %x\n", (int)offset
);
113 static CPUReadMemoryFunc
* const pl050_readfn
[] = {
119 static CPUWriteMemoryFunc
* const pl050_writefn
[] = {
125 static int pl050_init(SysBusDevice
*dev
, int is_mouse
)
127 pl050_state
*s
= FROM_SYSBUS(pl050_state
, dev
);
130 iomemtype
= cpu_register_io_memory(pl050_readfn
,
132 DEVICE_NATIVE_ENDIAN
);
133 sysbus_init_mmio(dev
, 0x1000, iomemtype
);
134 sysbus_init_irq(dev
, &s
->irq
);
135 s
->is_mouse
= is_mouse
;
137 s
->dev
= ps2_mouse_init(pl050_update
, s
);
139 s
->dev
= ps2_kbd_init(pl050_update
, s
);
140 /* ??? Save/restore. */
144 static int pl050_init_keyboard(SysBusDevice
*dev
)
146 return pl050_init(dev
, 0);
149 static int pl050_init_mouse(SysBusDevice
*dev
)
151 return pl050_init(dev
, 1);
154 static void pl050_register_devices(void)
156 sysbus_register_dev("pl050_keyboard", sizeof(pl050_state
),
157 pl050_init_keyboard
);
158 sysbus_register_dev("pl050_mouse", sizeof(pl050_state
),
162 device_init(pl050_register_devices
)