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
|
|
|
|
*
|
|
|
|
* This code is licenced under the GPL.
|
|
|
|
*/
|
|
|
|
|
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;
|
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;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2009-10-01 23:12:16 +02:00
|
|
|
static uint32_t pl050_read(void *opaque, target_phys_addr_t offset)
|
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,
|
2006-04-09 03:32:52 +02:00
|
|
|
uint32_t value)
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2009-08-25 20:29:31 +02:00
|
|
|
static CPUReadMemoryFunc * const pl050_readfn[] = {
|
2006-04-09 03:32:52 +02:00
|
|
|
pl050_read,
|
|
|
|
pl050_read,
|
|
|
|
pl050_read
|
|
|
|
};
|
|
|
|
|
2009-08-25 20:29:31 +02:00
|
|
|
static CPUWriteMemoryFunc * const pl050_writefn[] = {
|
2006-04-09 03:32:52 +02:00
|
|
|
pl050_write,
|
|
|
|
pl050_write,
|
|
|
|
pl050_write
|
|
|
|
};
|
|
|
|
|
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
|
|
|
int iomemtype;
|
|
|
|
|
2009-06-14 10:38:51 +02:00
|
|
|
iomemtype = cpu_register_io_memory(pl050_readfn,
|
2006-04-09 03:32:52 +02:00
|
|
|
pl050_writefn, s);
|
2009-05-14 23:35:07 +02:00
|
|
|
sysbus_init_mmio(dev, 0x1000, iomemtype);
|
|
|
|
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);
|
|
|
|
/* ??? Save/restore. */
|
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
|
|
|
}
|
|
|
|
|
|
|
|
static void pl050_register_devices(void)
|
|
|
|
{
|
|
|
|
sysbus_register_dev("pl050_keyboard", sizeof(pl050_state),
|
|
|
|
pl050_init_keyboard);
|
|
|
|
sysbus_register_dev("pl050_mouse", sizeof(pl050_state),
|
|
|
|
pl050_init_mouse);
|
|
|
|
}
|
|
|
|
|
|
|
|
device_init(pl050_register_devices)
|