xref: /qemu/hw/input/lasips2.c (revision d0af5d6a400974ee508e9ca3da6b1784bea5322a)
12a6505b0SSven Schnelle /*
22a6505b0SSven Schnelle  * QEMU HP Lasi PS/2 interface emulation
32a6505b0SSven Schnelle  *
42a6505b0SSven Schnelle  * Copyright (c) 2019 Sven Schnelle
52a6505b0SSven Schnelle  *
62a6505b0SSven Schnelle  * Permission is hereby granted, free of charge, to any person obtaining a copy
72a6505b0SSven Schnelle  * of this software and associated documentation files (the "Software"), to deal
82a6505b0SSven Schnelle  * in the Software without restriction, including without limitation the rights
92a6505b0SSven Schnelle  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
102a6505b0SSven Schnelle  * copies of the Software, and to permit persons to whom the Software is
112a6505b0SSven Schnelle  * furnished to do so, subject to the following conditions:
122a6505b0SSven Schnelle  *
132a6505b0SSven Schnelle  * The above copyright notice and this permission notice shall be included in
142a6505b0SSven Schnelle  * all copies or substantial portions of the Software.
152a6505b0SSven Schnelle  *
162a6505b0SSven Schnelle  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
172a6505b0SSven Schnelle  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
182a6505b0SSven Schnelle  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
192a6505b0SSven Schnelle  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
202a6505b0SSven Schnelle  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
212a6505b0SSven Schnelle  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
222a6505b0SSven Schnelle  * THE SOFTWARE.
232a6505b0SSven Schnelle  */
242a6505b0SSven Schnelle #include "qemu/osdep.h"
252a6505b0SSven Schnelle #include "qemu/log.h"
262a6505b0SSven Schnelle #include "hw/qdev-properties.h"
27653b388cSMark Cave-Ayland #include "hw/sysbus.h"
282a6505b0SSven Schnelle #include "hw/input/ps2.h"
292a6505b0SSven Schnelle #include "hw/input/lasips2.h"
302a6505b0SSven Schnelle #include "exec/hwaddr.h"
312a6505b0SSven Schnelle #include "trace.h"
322a6505b0SSven Schnelle #include "exec/address-spaces.h"
332a6505b0SSven Schnelle #include "migration/vmstate.h"
342a6505b0SSven Schnelle #include "hw/irq.h"
35653b388cSMark Cave-Ayland #include "qapi/error.h"
362a6505b0SSven Schnelle 
372a6505b0SSven Schnelle 
382a6505b0SSven Schnelle static const VMStateDescription vmstate_lasips2 = {
392a6505b0SSven Schnelle     .name = "lasips2",
402a6505b0SSven Schnelle     .version_id = 0,
412a6505b0SSven Schnelle     .minimum_version_id = 0,
422a6505b0SSven Schnelle     .fields = (VMStateField[]) {
43b7047733SMark Cave-Ayland         VMSTATE_UINT8(kbd_port.parent_obj.control, LASIPS2State),
44b7047733SMark Cave-Ayland         VMSTATE_UINT8(kbd_port.parent_obj.id, LASIPS2State),
45c553d6c0SMark Cave-Ayland         VMSTATE_BOOL(kbd_port.parent_obj.birq, LASIPS2State),
46a088ce9bSMark Cave-Ayland         VMSTATE_UINT8(mouse_port.parent_obj.control, LASIPS2State),
47a088ce9bSMark Cave-Ayland         VMSTATE_UINT8(mouse_port.parent_obj.id, LASIPS2State),
48c553d6c0SMark Cave-Ayland         VMSTATE_BOOL(mouse_port.parent_obj.birq, LASIPS2State),
492a6505b0SSven Schnelle         VMSTATE_END_OF_LIST()
502a6505b0SSven Schnelle     }
512a6505b0SSven Schnelle };
522a6505b0SSven Schnelle 
532a6505b0SSven Schnelle typedef enum {
542a6505b0SSven Schnelle     REG_PS2_ID = 0,
552a6505b0SSven Schnelle     REG_PS2_RCVDATA = 4,
562a6505b0SSven Schnelle     REG_PS2_CONTROL = 8,
572a6505b0SSven Schnelle     REG_PS2_STATUS = 12,
582a6505b0SSven Schnelle } lasips2_read_reg_t;
592a6505b0SSven Schnelle 
602a6505b0SSven Schnelle typedef enum {
612a6505b0SSven Schnelle     REG_PS2_RESET = 0,
622a6505b0SSven Schnelle     REG_PS2_XMTDATA = 4,
632a6505b0SSven Schnelle } lasips2_write_reg_t;
642a6505b0SSven Schnelle 
652a6505b0SSven Schnelle typedef enum {
662a6505b0SSven Schnelle     LASIPS2_CONTROL_ENABLE = 0x01,
672a6505b0SSven Schnelle     LASIPS2_CONTROL_LOOPBACK = 0x02,
682a6505b0SSven Schnelle     LASIPS2_CONTROL_DIAG = 0x20,
692a6505b0SSven Schnelle     LASIPS2_CONTROL_DATDIR = 0x40,
702a6505b0SSven Schnelle     LASIPS2_CONTROL_CLKDIR = 0x80,
712a6505b0SSven Schnelle } lasips2_control_reg_t;
722a6505b0SSven Schnelle 
732a6505b0SSven Schnelle typedef enum {
742a6505b0SSven Schnelle     LASIPS2_STATUS_RBNE = 0x01,
752a6505b0SSven Schnelle     LASIPS2_STATUS_TBNE = 0x02,
762a6505b0SSven Schnelle     LASIPS2_STATUS_TERR = 0x04,
772a6505b0SSven Schnelle     LASIPS2_STATUS_PERR = 0x08,
782a6505b0SSven Schnelle     LASIPS2_STATUS_CMPINTR = 0x10,
792a6505b0SSven Schnelle     LASIPS2_STATUS_DATSHD = 0x40,
802a6505b0SSven Schnelle     LASIPS2_STATUS_CLKSHD = 0x80,
812a6505b0SSven Schnelle } lasips2_status_reg_t;
822a6505b0SSven Schnelle 
835d2bd735SPhilippe Mathieu-Daudé static const char *lasips2_read_reg_name(uint64_t addr)
842a6505b0SSven Schnelle {
852a6505b0SSven Schnelle     switch (addr & 0xc) {
862a6505b0SSven Schnelle     case REG_PS2_ID:
872a6505b0SSven Schnelle         return " PS2_ID";
882a6505b0SSven Schnelle 
892a6505b0SSven Schnelle     case REG_PS2_RCVDATA:
902a6505b0SSven Schnelle         return " PS2_RCVDATA";
912a6505b0SSven Schnelle 
922a6505b0SSven Schnelle     case REG_PS2_CONTROL:
932a6505b0SSven Schnelle         return " PS2_CONTROL";
942a6505b0SSven Schnelle 
952a6505b0SSven Schnelle     case REG_PS2_STATUS:
962a6505b0SSven Schnelle         return " PS2_STATUS";
972a6505b0SSven Schnelle 
982a6505b0SSven Schnelle     default:
992a6505b0SSven Schnelle         return "";
1002a6505b0SSven Schnelle     }
1012a6505b0SSven Schnelle }
1022a6505b0SSven Schnelle 
1035d2bd735SPhilippe Mathieu-Daudé static const char *lasips2_write_reg_name(uint64_t addr)
1042a6505b0SSven Schnelle {
1052a6505b0SSven Schnelle     switch (addr & 0x0c) {
1062a6505b0SSven Schnelle     case REG_PS2_RESET:
1072a6505b0SSven Schnelle         return " PS2_RESET";
1082a6505b0SSven Schnelle 
1092a6505b0SSven Schnelle     case REG_PS2_XMTDATA:
1102a6505b0SSven Schnelle         return " PS2_XMTDATA";
1112a6505b0SSven Schnelle 
1122a6505b0SSven Schnelle     case REG_PS2_CONTROL:
1132a6505b0SSven Schnelle         return " PS2_CONTROL";
1142a6505b0SSven Schnelle 
1152a6505b0SSven Schnelle     default:
1162a6505b0SSven Schnelle         return "";
1172a6505b0SSven Schnelle     }
1182a6505b0SSven Schnelle }
1192a6505b0SSven Schnelle 
1202a6505b0SSven Schnelle static void lasips2_update_irq(LASIPS2State *s)
1212a6505b0SSven Schnelle {
122c553d6c0SMark Cave-Ayland     trace_lasips2_intr(s->kbd_port.parent_obj.birq |
123c553d6c0SMark Cave-Ayland                        s->mouse_port.parent_obj.birq);
124c553d6c0SMark Cave-Ayland     qemu_set_irq(s->irq, s->kbd_port.parent_obj.birq |
125c553d6c0SMark Cave-Ayland                          s->mouse_port.parent_obj.birq);
1262a6505b0SSven Schnelle }
1272a6505b0SSven Schnelle 
1282a6505b0SSven Schnelle static void lasips2_reg_write(void *opaque, hwaddr addr, uint64_t val,
1292a6505b0SSven Schnelle                               unsigned size)
1302a6505b0SSven Schnelle {
1312a6505b0SSven Schnelle     LASIPS2Port *port = opaque;
1322a6505b0SSven Schnelle 
1332a6505b0SSven Schnelle     trace_lasips2_reg_write(size, port->id, addr,
1345d2bd735SPhilippe Mathieu-Daudé                             lasips2_write_reg_name(addr), val);
1352a6505b0SSven Schnelle 
1362a6505b0SSven Schnelle     switch (addr & 0xc) {
1372a6505b0SSven Schnelle     case REG_PS2_CONTROL:
1382a6505b0SSven Schnelle         port->control = val;
1392a6505b0SSven Schnelle         break;
1402a6505b0SSven Schnelle 
1412a6505b0SSven Schnelle     case REG_PS2_XMTDATA:
1422a6505b0SSven Schnelle         if (port->control & LASIPS2_CONTROL_LOOPBACK) {
1432a6505b0SSven Schnelle             port->buf = val;
144c553d6c0SMark Cave-Ayland             port->birq = true;
1452a6505b0SSven Schnelle             port->loopback_rbne = true;
1462a6505b0SSven Schnelle             lasips2_update_irq(port->parent);
1472a6505b0SSven Schnelle             break;
1482a6505b0SSven Schnelle         }
1492a6505b0SSven Schnelle 
1502a6505b0SSven Schnelle         if (port->id) {
151f4907cb5SMark Cave-Ayland             ps2_write_mouse(PS2_MOUSE_DEVICE(port->ps2dev), val);
1522a6505b0SSven Schnelle         } else {
153f4907cb5SMark Cave-Ayland             ps2_write_keyboard(PS2_KBD_DEVICE(port->ps2dev), val);
1542a6505b0SSven Schnelle         }
1552a6505b0SSven Schnelle         break;
1562a6505b0SSven Schnelle 
1572a6505b0SSven Schnelle     case REG_PS2_RESET:
1582a6505b0SSven Schnelle         break;
1592a6505b0SSven Schnelle 
1602a6505b0SSven Schnelle     default:
1612a6505b0SSven Schnelle         qemu_log_mask(LOG_UNIMP, "%s: unknown register 0x%02" HWADDR_PRIx "\n",
1622a6505b0SSven Schnelle                       __func__, addr);
1632a6505b0SSven Schnelle         break;
1642a6505b0SSven Schnelle     }
1652a6505b0SSven Schnelle }
1662a6505b0SSven Schnelle 
1672a6505b0SSven Schnelle static uint64_t lasips2_reg_read(void *opaque, hwaddr addr, unsigned size)
1682a6505b0SSven Schnelle {
1692a6505b0SSven Schnelle     LASIPS2Port *port = opaque;
1702a6505b0SSven Schnelle     uint64_t ret = 0;
1712a6505b0SSven Schnelle 
1722a6505b0SSven Schnelle     switch (addr & 0xc) {
1732a6505b0SSven Schnelle     case REG_PS2_ID:
1742a6505b0SSven Schnelle         ret = port->id;
1752a6505b0SSven Schnelle         break;
1762a6505b0SSven Schnelle 
1772a6505b0SSven Schnelle     case REG_PS2_RCVDATA:
1782a6505b0SSven Schnelle         if (port->control & LASIPS2_CONTROL_LOOPBACK) {
179c553d6c0SMark Cave-Ayland             port->birq = false;
1802a6505b0SSven Schnelle             port->loopback_rbne = false;
1812a6505b0SSven Schnelle             lasips2_update_irq(port->parent);
1822a6505b0SSven Schnelle             ret = port->buf;
1832a6505b0SSven Schnelle             break;
1842a6505b0SSven Schnelle         }
1852a6505b0SSven Schnelle 
186f4907cb5SMark Cave-Ayland         ret = ps2_read_data(port->ps2dev);
1872a6505b0SSven Schnelle         break;
1882a6505b0SSven Schnelle 
1892a6505b0SSven Schnelle     case REG_PS2_CONTROL:
1902a6505b0SSven Schnelle         ret = port->control;
1912a6505b0SSven Schnelle         break;
1922a6505b0SSven Schnelle 
1932a6505b0SSven Schnelle     case REG_PS2_STATUS:
1942a6505b0SSven Schnelle         ret = LASIPS2_STATUS_DATSHD | LASIPS2_STATUS_CLKSHD;
1952a6505b0SSven Schnelle 
1962a6505b0SSven Schnelle         if (port->control & LASIPS2_CONTROL_DIAG) {
1972a6505b0SSven Schnelle             if (!(port->control & LASIPS2_CONTROL_DATDIR)) {
1982a6505b0SSven Schnelle                 ret &= ~LASIPS2_STATUS_DATSHD;
1992a6505b0SSven Schnelle             }
2002a6505b0SSven Schnelle 
2012a6505b0SSven Schnelle             if (!(port->control & LASIPS2_CONTROL_CLKDIR)) {
2022a6505b0SSven Schnelle                 ret &= ~LASIPS2_STATUS_CLKSHD;
2032a6505b0SSven Schnelle             }
2042a6505b0SSven Schnelle         }
2052a6505b0SSven Schnelle 
2062a6505b0SSven Schnelle         if (port->control & LASIPS2_CONTROL_LOOPBACK) {
2072a6505b0SSven Schnelle             if (port->loopback_rbne) {
2082a6505b0SSven Schnelle                 ret |= LASIPS2_STATUS_RBNE;
2092a6505b0SSven Schnelle             }
2102a6505b0SSven Schnelle         } else {
211f4907cb5SMark Cave-Ayland             if (!ps2_queue_empty(port->ps2dev)) {
2122a6505b0SSven Schnelle                 ret |= LASIPS2_STATUS_RBNE;
2132a6505b0SSven Schnelle             }
2142a6505b0SSven Schnelle         }
2152a6505b0SSven Schnelle 
216c553d6c0SMark Cave-Ayland         if (port->parent->kbd_port.parent_obj.birq ||
217c553d6c0SMark Cave-Ayland             port->parent->mouse_port.parent_obj.birq) {
2182a6505b0SSven Schnelle                 ret |= LASIPS2_STATUS_CMPINTR;
2192a6505b0SSven Schnelle         }
2202a6505b0SSven Schnelle         break;
2212a6505b0SSven Schnelle 
2222a6505b0SSven Schnelle     default:
2232a6505b0SSven Schnelle         qemu_log_mask(LOG_UNIMP, "%s: unknown register 0x%02" HWADDR_PRIx "\n",
2242a6505b0SSven Schnelle                       __func__, addr);
2252a6505b0SSven Schnelle         break;
2262a6505b0SSven Schnelle     }
2272a93d3c1SMark Cave-Ayland 
2282a6505b0SSven Schnelle     trace_lasips2_reg_read(size, port->id, addr,
2295d2bd735SPhilippe Mathieu-Daudé                            lasips2_read_reg_name(addr), ret);
2302a6505b0SSven Schnelle     return ret;
2312a6505b0SSven Schnelle }
2322a6505b0SSven Schnelle 
2332a6505b0SSven Schnelle static const MemoryRegionOps lasips2_reg_ops = {
2342a6505b0SSven Schnelle     .read = lasips2_reg_read,
2352a6505b0SSven Schnelle     .write = lasips2_reg_write,
2362a6505b0SSven Schnelle     .impl = {
2372a6505b0SSven Schnelle         .min_access_size = 1,
2382a6505b0SSven Schnelle         .max_access_size = 4,
2392a6505b0SSven Schnelle     },
2402a6505b0SSven Schnelle     .endianness = DEVICE_NATIVE_ENDIAN,
2412a6505b0SSven Schnelle };
2422a6505b0SSven Schnelle 
2430d1ac496SMark Cave-Ayland static void lasips2_set_kbd_irq(void *opaque, int n, int level)
2442a6505b0SSven Schnelle {
2450d1ac496SMark Cave-Ayland     LASIPS2State *s = LASIPS2(opaque);
246b7047733SMark Cave-Ayland     LASIPS2Port *port = LASIPS2_PORT(&s->kbd_port);
2470d1ac496SMark Cave-Ayland 
248c553d6c0SMark Cave-Ayland     port->birq = level;
2490d1ac496SMark Cave-Ayland     lasips2_update_irq(port->parent);
2500d1ac496SMark Cave-Ayland }
2510d1ac496SMark Cave-Ayland 
2520d1ac496SMark Cave-Ayland static void lasips2_set_mouse_irq(void *opaque, int n, int level)
2530d1ac496SMark Cave-Ayland {
2540d1ac496SMark Cave-Ayland     LASIPS2State *s = LASIPS2(opaque);
255a088ce9bSMark Cave-Ayland     LASIPS2Port *port = LASIPS2_PORT(&s->mouse_port);
2562a93d3c1SMark Cave-Ayland 
257c553d6c0SMark Cave-Ayland     port->birq = level;
2582a6505b0SSven Schnelle     lasips2_update_irq(port->parent);
2592a6505b0SSven Schnelle }
2602a6505b0SSven Schnelle 
2611702627cSMark Cave-Ayland static void lasips2_realize(DeviceState *dev, Error **errp)
2621702627cSMark Cave-Ayland {
2631702627cSMark Cave-Ayland     LASIPS2State *s = LASIPS2(dev);
264b7047733SMark Cave-Ayland     LASIPS2Port *lp;
2651702627cSMark Cave-Ayland 
266b7047733SMark Cave-Ayland     lp = LASIPS2_PORT(&s->kbd_port);
267b7047733SMark Cave-Ayland     if (!(qdev_realize(DEVICE(lp), NULL, errp))) {
268b7047733SMark Cave-Ayland         return;
269b7047733SMark Cave-Ayland     }
270b7047733SMark Cave-Ayland 
271b7047733SMark Cave-Ayland     qdev_connect_gpio_out(DEVICE(lp->ps2dev), PS2_DEVICE_IRQ,
2720d1ac496SMark Cave-Ayland                           qdev_get_gpio_in_named(dev, "ps2-kbd-input-irq",
2730d1ac496SMark Cave-Ayland                                                  0));
274a088ce9bSMark Cave-Ayland 
275a088ce9bSMark Cave-Ayland     lp = LASIPS2_PORT(&s->mouse_port);
276a088ce9bSMark Cave-Ayland     if (!(qdev_realize(DEVICE(lp), NULL, errp))) {
277a088ce9bSMark Cave-Ayland         return;
278a088ce9bSMark Cave-Ayland     }
279a088ce9bSMark Cave-Ayland 
280a088ce9bSMark Cave-Ayland     qdev_connect_gpio_out(DEVICE(lp->ps2dev), PS2_DEVICE_IRQ,
2810d1ac496SMark Cave-Ayland                           qdev_get_gpio_in_named(dev, "ps2-mouse-input-irq",
2820d1ac496SMark Cave-Ayland                                                  0));
2832a6505b0SSven Schnelle }
284653b388cSMark Cave-Ayland 
28563195aa5SMark Cave-Ayland static void lasips2_init(Object *obj)
28663195aa5SMark Cave-Ayland {
28763195aa5SMark Cave-Ayland     LASIPS2State *s = LASIPS2(obj);
288b7047733SMark Cave-Ayland     LASIPS2Port *lp;
28963195aa5SMark Cave-Ayland 
290b7047733SMark Cave-Ayland     object_initialize_child(obj, "lasips2-kbd-port", &s->kbd_port,
291b7047733SMark Cave-Ayland                             TYPE_LASIPS2_KBD_PORT);
292a088ce9bSMark Cave-Ayland     object_initialize_child(obj, "lasips2-mouse-port", &s->mouse_port,
293a088ce9bSMark Cave-Ayland                             TYPE_LASIPS2_MOUSE_PORT);
29463195aa5SMark Cave-Ayland 
295b7047733SMark Cave-Ayland     lp = LASIPS2_PORT(&s->kbd_port);
296b7047733SMark Cave-Ayland     sysbus_init_mmio(SYS_BUS_DEVICE(obj), &lp->reg);
297a088ce9bSMark Cave-Ayland     lp = LASIPS2_PORT(&s->mouse_port);
298a088ce9bSMark Cave-Ayland     sysbus_init_mmio(SYS_BUS_DEVICE(obj), &lp->reg);
29997bc0597SMark Cave-Ayland 
30097bc0597SMark Cave-Ayland     sysbus_init_irq(SYS_BUS_DEVICE(obj), &s->irq);
3010d1ac496SMark Cave-Ayland 
3020d1ac496SMark Cave-Ayland     qdev_init_gpio_in_named(DEVICE(obj), lasips2_set_kbd_irq,
3030d1ac496SMark Cave-Ayland                             "ps2-kbd-input-irq", 1);
3040d1ac496SMark Cave-Ayland     qdev_init_gpio_in_named(DEVICE(obj), lasips2_set_mouse_irq,
3050d1ac496SMark Cave-Ayland                             "ps2-mouse-input-irq", 1);
30663195aa5SMark Cave-Ayland }
30763195aa5SMark Cave-Ayland 
30842119fdbSMark Cave-Ayland static void lasips2_class_init(ObjectClass *klass, void *data)
30942119fdbSMark Cave-Ayland {
31042119fdbSMark Cave-Ayland     DeviceClass *dc = DEVICE_CLASS(klass);
31142119fdbSMark Cave-Ayland 
3121702627cSMark Cave-Ayland     dc->realize = lasips2_realize;
31317b8013aSMark Cave-Ayland     dc->vmsd = &vmstate_lasips2;
31442119fdbSMark Cave-Ayland     set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
31542119fdbSMark Cave-Ayland }
31642119fdbSMark Cave-Ayland 
317653b388cSMark Cave-Ayland static const TypeInfo lasips2_info = {
318653b388cSMark Cave-Ayland     .name          = TYPE_LASIPS2,
319653b388cSMark Cave-Ayland     .parent        = TYPE_SYS_BUS_DEVICE,
32063195aa5SMark Cave-Ayland     .instance_init = lasips2_init,
32142119fdbSMark Cave-Ayland     .instance_size = sizeof(LASIPS2State),
32242119fdbSMark Cave-Ayland     .class_init    = lasips2_class_init,
323653b388cSMark Cave-Ayland };
324653b388cSMark Cave-Ayland 
325*d0af5d6aSMark Cave-Ayland static void lasips2_port_set_irq(void *opaque, int n, int level)
326*d0af5d6aSMark Cave-Ayland {
327*d0af5d6aSMark Cave-Ayland     LASIPS2Port *s = LASIPS2_PORT(opaque);
328*d0af5d6aSMark Cave-Ayland 
329*d0af5d6aSMark Cave-Ayland     qemu_set_irq(s->irq, level);
330*d0af5d6aSMark Cave-Ayland }
331*d0af5d6aSMark Cave-Ayland 
332*d0af5d6aSMark Cave-Ayland static void lasips2_port_realize(DeviceState *dev, Error **errp)
333*d0af5d6aSMark Cave-Ayland {
334*d0af5d6aSMark Cave-Ayland     LASIPS2Port *s = LASIPS2_PORT(dev);
335*d0af5d6aSMark Cave-Ayland 
336*d0af5d6aSMark Cave-Ayland     qdev_connect_gpio_out(DEVICE(s->ps2dev), PS2_DEVICE_IRQ,
337*d0af5d6aSMark Cave-Ayland                           qdev_get_gpio_in_named(dev, "ps2-input-irq", 0));
338*d0af5d6aSMark Cave-Ayland }
339*d0af5d6aSMark Cave-Ayland 
3408db817beSMark Cave-Ayland static void lasips2_port_init(Object *obj)
3418db817beSMark Cave-Ayland {
3428db817beSMark Cave-Ayland     LASIPS2Port *s = LASIPS2_PORT(obj);
3438db817beSMark Cave-Ayland 
3448db817beSMark Cave-Ayland     qdev_init_gpio_out(DEVICE(obj), &s->irq, 1);
345*d0af5d6aSMark Cave-Ayland     qdev_init_gpio_in_named(DEVICE(obj), lasips2_port_set_irq,
346*d0af5d6aSMark Cave-Ayland                             "ps2-input-irq", 1);
347*d0af5d6aSMark Cave-Ayland }
348*d0af5d6aSMark Cave-Ayland 
349*d0af5d6aSMark Cave-Ayland static void lasips2_port_class_init(ObjectClass *klass, void *data)
350*d0af5d6aSMark Cave-Ayland {
351*d0af5d6aSMark Cave-Ayland     DeviceClass *dc = DEVICE_CLASS(klass);
352*d0af5d6aSMark Cave-Ayland 
353*d0af5d6aSMark Cave-Ayland     dc->realize = lasips2_port_realize;
3548db817beSMark Cave-Ayland }
3558db817beSMark Cave-Ayland 
356f8d89a7dSMark Cave-Ayland static const TypeInfo lasips2_port_info = {
357f8d89a7dSMark Cave-Ayland     .name          = TYPE_LASIPS2_PORT,
358f8d89a7dSMark Cave-Ayland     .parent        = TYPE_DEVICE,
3598db817beSMark Cave-Ayland     .instance_init = lasips2_port_init,
360f8d89a7dSMark Cave-Ayland     .instance_size = sizeof(LASIPS2Port),
36162201e43SMark Cave-Ayland     .class_init    = lasips2_port_class_init,
36262201e43SMark Cave-Ayland     .class_size    = sizeof(LASIPS2PortDeviceClass),
363f8d89a7dSMark Cave-Ayland     .abstract      = true,
364f8d89a7dSMark Cave-Ayland };
365f8d89a7dSMark Cave-Ayland 
366b41eee94SMark Cave-Ayland static void lasips2_kbd_port_realize(DeviceState *dev, Error **errp)
367b41eee94SMark Cave-Ayland {
368b41eee94SMark Cave-Ayland     LASIPS2Port *lp = LASIPS2_PORT(dev);
369b41eee94SMark Cave-Ayland 
370b41eee94SMark Cave-Ayland     lp->ps2dev = ps2_kbd_init();
371b41eee94SMark Cave-Ayland }
372b41eee94SMark Cave-Ayland 
373b7047733SMark Cave-Ayland static void lasips2_kbd_port_init(Object *obj)
374b7047733SMark Cave-Ayland {
375b7047733SMark Cave-Ayland     LASIPS2KbdPort *s = LASIPS2_KBD_PORT(obj);
376b7047733SMark Cave-Ayland     LASIPS2Port *lp = LASIPS2_PORT(obj);
377b7047733SMark Cave-Ayland 
378b7047733SMark Cave-Ayland     memory_region_init_io(&lp->reg, obj, &lasips2_reg_ops, lp, "lasips2-kbd",
379b7047733SMark Cave-Ayland                           0x100);
380b7047733SMark Cave-Ayland     lp->id = 0;
381b7047733SMark Cave-Ayland     lp->parent = container_of(s, LASIPS2State, kbd_port);
382b7047733SMark Cave-Ayland }
383b7047733SMark Cave-Ayland 
384b41eee94SMark Cave-Ayland static void lasips2_kbd_port_class_init(ObjectClass *klass, void *data)
385b41eee94SMark Cave-Ayland {
386b41eee94SMark Cave-Ayland     DeviceClass *dc = DEVICE_CLASS(klass);
387*d0af5d6aSMark Cave-Ayland     LASIPS2PortDeviceClass *lpdc = LASIPS2_PORT_CLASS(klass);
388b41eee94SMark Cave-Ayland 
389*d0af5d6aSMark Cave-Ayland     device_class_set_parent_realize(dc, lasips2_kbd_port_realize,
390*d0af5d6aSMark Cave-Ayland                                     &lpdc->parent_realize);
391b41eee94SMark Cave-Ayland }
392b41eee94SMark Cave-Ayland 
393ef90a06fSMark Cave-Ayland static const TypeInfo lasips2_kbd_port_info = {
394ef90a06fSMark Cave-Ayland     .name          = TYPE_LASIPS2_KBD_PORT,
395ef90a06fSMark Cave-Ayland     .parent        = TYPE_LASIPS2_PORT,
396ef90a06fSMark Cave-Ayland     .instance_size = sizeof(LASIPS2KbdPort),
397b7047733SMark Cave-Ayland     .instance_init = lasips2_kbd_port_init,
398b41eee94SMark Cave-Ayland     .class_init    = lasips2_kbd_port_class_init,
399ef90a06fSMark Cave-Ayland };
400ef90a06fSMark Cave-Ayland 
4018d490f8dSMark Cave-Ayland static void lasips2_mouse_port_realize(DeviceState *dev, Error **errp)
4028d490f8dSMark Cave-Ayland {
4038d490f8dSMark Cave-Ayland     LASIPS2Port *lp = LASIPS2_PORT(dev);
4048d490f8dSMark Cave-Ayland 
4058d490f8dSMark Cave-Ayland     lp->ps2dev = ps2_mouse_init();
4068d490f8dSMark Cave-Ayland }
4078d490f8dSMark Cave-Ayland 
408a088ce9bSMark Cave-Ayland static void lasips2_mouse_port_init(Object *obj)
409a088ce9bSMark Cave-Ayland {
410a088ce9bSMark Cave-Ayland     LASIPS2MousePort *s = LASIPS2_MOUSE_PORT(obj);
411a088ce9bSMark Cave-Ayland     LASIPS2Port *lp = LASIPS2_PORT(obj);
412a088ce9bSMark Cave-Ayland 
413a088ce9bSMark Cave-Ayland     memory_region_init_io(&lp->reg, obj, &lasips2_reg_ops, lp, "lasips2-mouse",
414a088ce9bSMark Cave-Ayland                           0x100);
415a088ce9bSMark Cave-Ayland     lp->id = 1;
416a088ce9bSMark Cave-Ayland     lp->parent = container_of(s, LASIPS2State, mouse_port);
417a088ce9bSMark Cave-Ayland }
418a088ce9bSMark Cave-Ayland 
4198d490f8dSMark Cave-Ayland static void lasips2_mouse_port_class_init(ObjectClass *klass, void *data)
4208d490f8dSMark Cave-Ayland {
4218d490f8dSMark Cave-Ayland     DeviceClass *dc = DEVICE_CLASS(klass);
422*d0af5d6aSMark Cave-Ayland     LASIPS2PortDeviceClass *lpdc = LASIPS2_PORT_CLASS(klass);
4238d490f8dSMark Cave-Ayland 
424*d0af5d6aSMark Cave-Ayland     device_class_set_parent_realize(dc, lasips2_mouse_port_realize,
425*d0af5d6aSMark Cave-Ayland                                     &lpdc->parent_realize);
4268d490f8dSMark Cave-Ayland }
4278d490f8dSMark Cave-Ayland 
428cb5827ceSMark Cave-Ayland static const TypeInfo lasips2_mouse_port_info = {
429cb5827ceSMark Cave-Ayland     .name          = TYPE_LASIPS2_MOUSE_PORT,
430cb5827ceSMark Cave-Ayland     .parent        = TYPE_LASIPS2_PORT,
431cb5827ceSMark Cave-Ayland     .instance_size = sizeof(LASIPS2MousePort),
432a088ce9bSMark Cave-Ayland     .instance_init = lasips2_mouse_port_init,
4338d490f8dSMark Cave-Ayland     .class_init    = lasips2_mouse_port_class_init,
434cb5827ceSMark Cave-Ayland };
435cb5827ceSMark Cave-Ayland 
436653b388cSMark Cave-Ayland static void lasips2_register_types(void)
437653b388cSMark Cave-Ayland {
438653b388cSMark Cave-Ayland     type_register_static(&lasips2_info);
439f8d89a7dSMark Cave-Ayland     type_register_static(&lasips2_port_info);
440ef90a06fSMark Cave-Ayland     type_register_static(&lasips2_kbd_port_info);
441cb5827ceSMark Cave-Ayland     type_register_static(&lasips2_mouse_port_info);
442653b388cSMark Cave-Ayland }
443653b388cSMark Cave-Ayland 
444653b388cSMark Cave-Ayland type_init(lasips2_register_types)
445