2007-09-16 23:08:06 +02:00
|
|
|
/*
|
2006-07-17 20:45:34 +02:00
|
|
|
* Arm PrimeCell PL050 Keyboard / Mouse Interface
|
2006-04-09 03:32:52 +02:00
|
|
|
*
|
2007-04-30 04:39:55 +02:00
|
|
|
* Copyright (c) 2006-2007 CodeSourcery.
|
2006-04-09 03:32:52 +02:00
|
|
|
* Written by Paul Brook
|
|
|
|
*
|
2011-06-26 04:21:35 +02:00
|
|
|
* This code is licensed under the GPL.
|
2006-04-09 03:32:52 +02:00
|
|
|
*/
|
|
|
|
|
2009-05-14 23:35:07 +02:00
|
|
|
#include "sysbus.h"
|
2007-11-17 18:14:51 +01:00
|
|
|
#include "ps2.h"
|
2006-04-09 03:32:52 +02:00
|
|
|
|
|
|
|
typedef struct {
|
2009-05-14 23:35:07 +02:00
|
|
|
SysBusDevice busdev;
|
2011-10-10 17:18:44 +02:00
|
|
|
MemoryRegion iomem;
|
2006-04-09 03:32:52 +02:00
|
|
|
void *dev;
|
|
|
|
uint32_t cr;
|
|
|
|
uint32_t clk;
|
|
|
|
uint32_t last;
|
|
|
|
int pending;
|
2007-04-07 20:14:41 +02:00
|
|
|
qemu_irq irq;
|
2006-04-09 03:32:52 +02:00
|
|
|
int is_mouse;
|
|
|
|
} pl050_state;
|
|
|
|
|
2010-12-23 18:19:54 +01:00
|
|
|
static const VMStateDescription vmstate_pl050 = {
|
|
|
|
.name = "pl050",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_UINT32(cr, pl050_state),
|
|
|
|
VMSTATE_UINT32(clk, pl050_state),
|
|
|
|
VMSTATE_UINT32(last, pl050_state),
|
|
|
|
VMSTATE_INT32(pending, pl050_state),
|
|
|
|
VMSTATE_INT32(is_mouse, pl050_state),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2007-04-30 04:39:55 +02:00
|
|
|
#define PL050_TXEMPTY (1 << 6)
|
|
|
|
#define PL050_TXBUSY (1 << 5)
|
|
|
|
#define PL050_RXFULL (1 << 4)
|
|
|
|
#define PL050_RXBUSY (1 << 3)
|
|
|
|
#define PL050_RXPARITY (1 << 2)
|
|
|
|
#define PL050_KMIC (1 << 1)
|
|
|
|
#define PL050_KMID (1 << 0)
|
|
|
|
|
2006-04-09 03:32:52 +02:00
|
|
|
static const unsigned char pl050_id[] =
|
|
|
|
{ 0x50, 0x10, 0x04, 0x00, 0x0d, 0xf0, 0x05, 0xb1 };
|
|
|
|
|
|
|
|
static void pl050_update(void *opaque, int level)
|
|
|
|
{
|
|
|
|
pl050_state *s = (pl050_state *)opaque;
|
|
|
|
int raise;
|
|
|
|
|
|
|
|
s->pending = level;
|
|
|
|
raise = (s->pending && (s->cr & 0x10) != 0)
|
|
|
|
|| (s->cr & 0x08) != 0;
|
2007-04-07 20:14:41 +02:00
|
|
|
qemu_set_irq(s->irq, raise);
|
2006-04-09 03:32:52 +02:00
|
|
|
}
|
|
|
|
|
2011-10-10 17:18:44 +02:00
|
|
|
static uint64_t pl050_read(void *opaque, target_phys_addr_t offset,
|
|
|
|
unsigned size)
|
2006-04-09 03:32:52 +02:00
|
|
|
{
|
|
|
|
pl050_state *s = (pl050_state *)opaque;
|
|
|
|
if (offset >= 0xfe0 && offset < 0x1000)
|
|
|
|
return pl050_id[(offset - 0xfe0) >> 2];
|
|
|
|
|
|
|
|
switch (offset >> 2) {
|
|
|
|
case 0: /* KMICR */
|
|
|
|
return s->cr;
|
|
|
|
case 1: /* KMISTAT */
|
2007-04-30 04:39:55 +02:00
|
|
|
{
|
|
|
|
uint8_t val;
|
|
|
|
uint32_t stat;
|
|
|
|
|
|
|
|
val = s->last;
|
|
|
|
val = val ^ (val >> 4);
|
|
|
|
val = val ^ (val >> 2);
|
|
|
|
val = (val ^ (val >> 1)) & 1;
|
|
|
|
|
|
|
|
stat = PL050_TXEMPTY;
|
|
|
|
if (val)
|
|
|
|
stat |= PL050_RXPARITY;
|
|
|
|
if (s->pending)
|
|
|
|
stat |= PL050_RXFULL;
|
|
|
|
|
|
|
|
return stat;
|
2006-04-09 03:32:52 +02:00
|
|
|
}
|
|
|
|
case 2: /* KMIDATA */
|
|
|
|
if (s->pending)
|
|
|
|
s->last = ps2_read_data(s->dev);
|
|
|
|
return s->last;
|
|
|
|
case 3: /* KMICLKDIV */
|
|
|
|
return s->clk;
|
|
|
|
case 4: /* KMIIR */
|
|
|
|
return s->pending | 2;
|
|
|
|
default:
|
2009-05-08 03:35:15 +02:00
|
|
|
hw_error("pl050_read: Bad offset %x\n", (int)offset);
|
2006-04-09 03:32:52 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-01 23:12:16 +02:00
|
|
|
static void pl050_write(void *opaque, target_phys_addr_t offset,
|
2011-10-10 17:18:44 +02:00
|
|
|
uint64_t value, unsigned size)
|
2006-04-09 03:32:52 +02:00
|
|
|
{
|
|
|
|
pl050_state *s = (pl050_state *)opaque;
|
|
|
|
switch (offset >> 2) {
|
|
|
|
case 0: /* KMICR */
|
|
|
|
s->cr = value;
|
|
|
|
pl050_update(s, s->pending);
|
|
|
|
/* ??? Need to implement the enable/disable bit. */
|
|
|
|
break;
|
|
|
|
case 2: /* KMIDATA */
|
|
|
|
/* ??? This should toggle the TX interrupt line. */
|
|
|
|
/* ??? This means kbd/mouse can block each other. */
|
|
|
|
if (s->is_mouse) {
|
|
|
|
ps2_write_mouse(s->dev, value);
|
|
|
|
} else {
|
|
|
|
ps2_write_keyboard(s->dev, value);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3: /* KMICLKDIV */
|
|
|
|
s->clk = value;
|
|
|
|
return;
|
|
|
|
default:
|
2009-05-08 03:35:15 +02:00
|
|
|
hw_error("pl050_write: Bad offset %x\n", (int)offset);
|
2006-04-09 03:32:52 +02:00
|
|
|
}
|
|
|
|
}
|
2011-10-10 17:18:44 +02:00
|
|
|
static const MemoryRegionOps pl050_ops = {
|
|
|
|
.read = pl050_read,
|
|
|
|
.write = pl050_write,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2006-04-09 03:32:52 +02:00
|
|
|
};
|
|
|
|
|
2009-08-14 10:36:05 +02:00
|
|
|
static int pl050_init(SysBusDevice *dev, int is_mouse)
|
2006-04-09 03:32:52 +02:00
|
|
|
{
|
2009-05-14 23:35:07 +02:00
|
|
|
pl050_state *s = FROM_SYSBUS(pl050_state, dev);
|
2006-04-09 03:32:52 +02:00
|
|
|
|
2011-10-10 17:18:44 +02:00
|
|
|
memory_region_init_io(&s->iomem, &pl050_ops, s, "pl050", 0x1000);
|
2011-11-27 10:38:10 +01:00
|
|
|
sysbus_init_mmio(dev, &s->iomem);
|
2009-05-14 23:35:07 +02:00
|
|
|
sysbus_init_irq(dev, &s->irq);
|
2006-04-09 03:32:52 +02:00
|
|
|
s->is_mouse = is_mouse;
|
2009-05-14 23:35:07 +02:00
|
|
|
if (s->is_mouse)
|
2006-04-09 03:32:52 +02:00
|
|
|
s->dev = ps2_mouse_init(pl050_update, s);
|
|
|
|
else
|
|
|
|
s->dev = ps2_kbd_init(pl050_update, s);
|
2009-08-14 10:36:05 +02:00
|
|
|
return 0;
|
2006-04-09 03:32:52 +02:00
|
|
|
}
|
2009-05-14 23:35:07 +02:00
|
|
|
|
2009-08-14 10:36:05 +02:00
|
|
|
static int pl050_init_keyboard(SysBusDevice *dev)
|
2009-05-14 23:35:07 +02:00
|
|
|
{
|
2009-08-14 10:36:05 +02:00
|
|
|
return pl050_init(dev, 0);
|
2009-05-14 23:35:07 +02:00
|
|
|
}
|
|
|
|
|
2009-08-14 10:36:05 +02:00
|
|
|
static int pl050_init_mouse(SysBusDevice *dev)
|
2009-05-14 23:35:07 +02:00
|
|
|
{
|
2009-08-14 10:36:05 +02:00
|
|
|
return pl050_init(dev, 1);
|
2009-05-14 23:35:07 +02:00
|
|
|
}
|
|
|
|
|
2012-01-24 20:12:29 +01:00
|
|
|
static void pl050_kbd_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2012-01-24 20:12:29 +01:00
|
|
|
SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
|
|
|
|
|
|
|
|
k->init = pl050_init_keyboard;
|
2011-12-08 04:34:16 +01:00
|
|
|
dc->vmsd = &vmstate_pl050;
|
2012-01-24 20:12:29 +01:00
|
|
|
}
|
|
|
|
|
2011-12-08 04:34:16 +01:00
|
|
|
static TypeInfo pl050_kbd_info = {
|
|
|
|
.name = "pl050_keyboard",
|
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(pl050_state),
|
|
|
|
.class_init = pl050_kbd_class_init,
|
2010-12-23 18:19:54 +01:00
|
|
|
};
|
|
|
|
|
2012-01-24 20:12:29 +01:00
|
|
|
static void pl050_mouse_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2012-01-24 20:12:29 +01:00
|
|
|
SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
|
|
|
|
|
|
|
|
k->init = pl050_init_mouse;
|
2011-12-08 04:34:16 +01:00
|
|
|
dc->vmsd = &vmstate_pl050;
|
2012-01-24 20:12:29 +01:00
|
|
|
}
|
|
|
|
|
2011-12-08 04:34:16 +01:00
|
|
|
static TypeInfo pl050_mouse_info = {
|
|
|
|
.name = "pl050_mouse",
|
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(pl050_state),
|
|
|
|
.class_init = pl050_mouse_class_init,
|
2010-12-23 18:19:54 +01:00
|
|
|
};
|
|
|
|
|
2009-05-14 23:35:07 +02:00
|
|
|
static void pl050_register_devices(void)
|
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
type_register_static(&pl050_kbd_info);
|
|
|
|
type_register_static(&pl050_mouse_info);
|
2009-05-14 23:35:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
device_init(pl050_register_devices)
|