2 * Arm PrimeCell PL050 Keyboard / Mouse Interface
4 * Copyright (c) 2006-2007 CodeSourcery.
5 * Written by Paul Brook
7 * This code is licensed under the GPL.
24 static const VMStateDescription vmstate_pl050
= {
27 .minimum_version_id
= 1,
28 .fields
= (VMStateField
[]) {
29 VMSTATE_UINT32(cr
, pl050_state
),
30 VMSTATE_UINT32(clk
, pl050_state
),
31 VMSTATE_UINT32(last
, pl050_state
),
32 VMSTATE_INT32(pending
, pl050_state
),
33 VMSTATE_INT32(is_mouse
, pl050_state
),
38 #define PL050_TXEMPTY (1 << 6)
39 #define PL050_TXBUSY (1 << 5)
40 #define PL050_RXFULL (1 << 4)
41 #define PL050_RXBUSY (1 << 3)
42 #define PL050_RXPARITY (1 << 2)
43 #define PL050_KMIC (1 << 1)
44 #define PL050_KMID (1 << 0)
46 static const unsigned char pl050_id
[] =
47 { 0x50, 0x10, 0x04, 0x00, 0x0d, 0xf0, 0x05, 0xb1 };
49 static void pl050_update(void *opaque
, int level
)
51 pl050_state
*s
= (pl050_state
*)opaque
;
55 raise
= (s
->pending
&& (s
->cr
& 0x10) != 0)
56 || (s
->cr
& 0x08) != 0;
57 qemu_set_irq(s
->irq
, raise
);
60 static uint32_t pl050_read(void *opaque
, target_phys_addr_t offset
)
62 pl050_state
*s
= (pl050_state
*)opaque
;
63 if (offset
>= 0xfe0 && offset
< 0x1000)
64 return pl050_id
[(offset
- 0xfe0) >> 2];
66 switch (offset
>> 2) {
75 val
= val
^ (val
>> 4);
76 val
= val
^ (val
>> 2);
77 val
= (val
^ (val
>> 1)) & 1;
81 stat
|= PL050_RXPARITY
;
89 s
->last
= ps2_read_data(s
->dev
);
91 case 3: /* KMICLKDIV */
94 return s
->pending
| 2;
96 hw_error("pl050_read: Bad offset %x\n", (int)offset
);
101 static void pl050_write(void *opaque
, target_phys_addr_t offset
,
104 pl050_state
*s
= (pl050_state
*)opaque
;
105 switch (offset
>> 2) {
108 pl050_update(s
, s
->pending
);
109 /* ??? Need to implement the enable/disable bit. */
111 case 2: /* KMIDATA */
112 /* ??? This should toggle the TX interrupt line. */
113 /* ??? This means kbd/mouse can block each other. */
115 ps2_write_mouse(s
->dev
, value
);
117 ps2_write_keyboard(s
->dev
, value
);
120 case 3: /* KMICLKDIV */
124 hw_error("pl050_write: Bad offset %x\n", (int)offset
);
127 static CPUReadMemoryFunc
* const pl050_readfn
[] = {
133 static CPUWriteMemoryFunc
* const pl050_writefn
[] = {
139 static int pl050_init(SysBusDevice
*dev
, int is_mouse
)
141 pl050_state
*s
= FROM_SYSBUS(pl050_state
, dev
);
144 iomemtype
= cpu_register_io_memory(pl050_readfn
,
146 DEVICE_NATIVE_ENDIAN
);
147 sysbus_init_mmio(dev
, 0x1000, iomemtype
);
148 sysbus_init_irq(dev
, &s
->irq
);
149 s
->is_mouse
= is_mouse
;
151 s
->dev
= ps2_mouse_init(pl050_update
, s
);
153 s
->dev
= ps2_kbd_init(pl050_update
, s
);
157 static int pl050_init_keyboard(SysBusDevice
*dev
)
159 return pl050_init(dev
, 0);
162 static int pl050_init_mouse(SysBusDevice
*dev
)
164 return pl050_init(dev
, 1);
167 static SysBusDeviceInfo pl050_kbd_info
= {
168 .init
= pl050_init_keyboard
,
169 .qdev
.name
= "pl050_keyboard",
170 .qdev
.size
= sizeof(pl050_state
),
171 .qdev
.vmsd
= &vmstate_pl050
,
174 static SysBusDeviceInfo pl050_mouse_info
= {
175 .init
= pl050_init_mouse
,
176 .qdev
.name
= "pl050_mouse",
177 .qdev
.size
= sizeof(pl050_state
),
178 .qdev
.vmsd
= &vmstate_pl050
,
181 static void pl050_register_devices(void)
183 sysbus_register_withprop(&pl050_kbd_info
);
184 sysbus_register_withprop(&pl050_mouse_info
);
187 device_init(pl050_register_devices
)