2 * QEMU ESCC (Z8030/Z8530/Z85C30/SCC/ESCC) serial port emulation
4 * Copyright (c) 2003-2005 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 #include "qemu/osdep.h"
27 #include "hw/qdev-properties.h"
28 #include "hw/sysbus.h"
29 #include "migration/vmstate.h"
30 #include "qemu/module.h"
31 #include "hw/char/escc.h"
32 #include "ui/console.h"
37 * "Z80C30/Z85C30/Z80230/Z85230/Z85233 SCC/ESCC User Manual",
38 * http://www.zilog.com/docs/serial/scc_escc_um.pdf
40 * On Sparc32 this is the serial port, mouse and keyboard part of chip STP2001
41 * (Slave I/O), also produced as NCR89C105. See
42 * http://www.ibiblio.org/pub/historic-linux/early-ports/Sparc/NCR/NCR89C105.txt
44 * The serial ports implement full AMD AM8530 or Zilog Z8530 chips,
45 * mouse and keyboard ports don't implement all functions and they are
46 * only asynchronous. There is no DMA.
48 * Z85C30 is also used on PowerMacs and m68k Macs.
50 * There are some small differences between Sparc version (sunzilog)
51 * and PowerMac (pmac):
52 * Offset between control and data registers
53 * There is some kind of lockup bug, but we can ignore it
55 * DMA on pmac using DBDMA chip
56 * pmac can do IRDA and faster rates, sunzilog can only do 38400
57 * pmac baud rate generator clock is 3.6864 MHz, sunzilog 4.9152 MHz
59 * Linux driver for m68k Macs is the same as for PowerMac (pmac_zilog),
60 * but registers are grouped by type and not by channel:
61 * channel is selected by bit 0 of the address (instead of bit 1)
62 * and register is selected by bit 1 of the address (instead of bit 0).
67 * 2006-Aug-10 Igor Kovalenko : Renamed KBDQueue to SERIOQueue, implemented
69 * Implemented serial mouse protocol.
71 * 2010-May-23 Artyom Tarasenko: Reworked IUS logic
74 #define CHN_C(s) ((s)->chn == escc_chn_b ? 'b' : 'a')
80 #define CMD_PTR_MASK 0x07
81 #define CMD_CMD_MASK 0x38
83 #define CMD_CLR_TXINT 0x28
84 #define CMD_CLR_IUS 0x38
86 #define INTR_INTALL 0x01
87 #define INTR_TXINT 0x02
88 #define INTR_RXMODEMSK 0x18
89 #define INTR_RXINT1ST 0x08
90 #define INTR_RXINTALL 0x10
93 #define RXCTRL_RXEN 0x01
95 #define TXCTRL1_PAREN 0x01
96 #define TXCTRL1_PAREV 0x02
97 #define TXCTRL1_1STOP 0x04
98 #define TXCTRL1_1HSTOP 0x08
99 #define TXCTRL1_2STOP 0x0c
100 #define TXCTRL1_STPMSK 0x0c
101 #define TXCTRL1_CLK1X 0x00
102 #define TXCTRL1_CLK16X 0x40
103 #define TXCTRL1_CLK32X 0x80
104 #define TXCTRL1_CLK64X 0xc0
105 #define TXCTRL1_CLKMSK 0xc0
107 #define TXCTRL2_TXEN 0x08
108 #define TXCTRL2_BITMSK 0x60
109 #define TXCTRL2_5BITS 0x00
110 #define TXCTRL2_7BITS 0x20
111 #define TXCTRL2_6BITS 0x40
112 #define TXCTRL2_8BITS 0x60
117 #define MINTR_STATUSHI 0x10
118 #define MINTR_RST_MASK 0xc0
119 #define MINTR_RST_B 0x40
120 #define MINTR_RST_A 0x80
121 #define MINTR_RST_ALL 0xc0
124 #define CLOCK_TRXC 0x08
128 #define MISC2_PLLDIS 0x30
130 #define EXTINT_DCD 0x08
131 #define EXTINT_SYNCINT 0x10
132 #define EXTINT_CTSINT 0x20
133 #define EXTINT_TXUNDRN 0x40
134 #define EXTINT_BRKINT 0x80
137 #define STATUS_RXAV 0x01
138 #define STATUS_ZERO 0x02
139 #define STATUS_TXEMPTY 0x04
140 #define STATUS_DCD 0x08
141 #define STATUS_SYNC 0x10
142 #define STATUS_CTS 0x20
143 #define STATUS_TXUNDRN 0x40
144 #define STATUS_BRK 0x80
146 #define SPEC_ALLSENT 0x01
147 #define SPEC_BITS8 0x06
149 #define IVEC_TXINTB 0x00
150 #define IVEC_LONOINT 0x06
151 #define IVEC_LORXINTA 0x0c
152 #define IVEC_LORXINTB 0x04
153 #define IVEC_LOTXINTA 0x08
154 #define IVEC_HINOINT 0x60
155 #define IVEC_HIRXINTA 0x30
156 #define IVEC_HIRXINTB 0x20
157 #define IVEC_HITXINTA 0x10
159 #define INTR_EXTINTB 0x01
160 #define INTR_TXINTB 0x02
161 #define INTR_RXINTB 0x04
162 #define INTR_EXTINTA 0x08
163 #define INTR_TXINTA 0x10
164 #define INTR_RXINTA 0x20
178 static void handle_kbd_command(ESCCChannelState
*s
, int val
);
179 static int serial_can_receive(void *opaque
);
180 static void serial_receive_byte(ESCCChannelState
*s
, int ch
);
182 static int reg_shift(ESCCState
*s
)
184 return s
->bit_swap
? s
->it_shift
+ 1 : s
->it_shift
;
187 static int chn_shift(ESCCState
*s
)
189 return s
->bit_swap
? s
->it_shift
: s
->it_shift
+ 1;
192 static void clear_queue(void *opaque
)
194 ESCCChannelState
*s
= opaque
;
195 ESCCSERIOQueue
*q
= &s
->queue
;
196 q
->rptr
= q
->wptr
= q
->count
= 0;
199 static void put_queue(void *opaque
, int b
)
201 ESCCChannelState
*s
= opaque
;
202 ESCCSERIOQueue
*q
= &s
->queue
;
204 trace_escc_put_queue(CHN_C(s
), b
);
205 if (q
->count
>= ESCC_SERIO_QUEUE_SIZE
) {
208 q
->data
[q
->wptr
] = b
;
209 if (++q
->wptr
== ESCC_SERIO_QUEUE_SIZE
) {
213 serial_receive_byte(s
, 0);
216 static uint32_t get_queue(void *opaque
)
218 ESCCChannelState
*s
= opaque
;
219 ESCCSERIOQueue
*q
= &s
->queue
;
225 val
= q
->data
[q
->rptr
];
226 if (++q
->rptr
== ESCC_SERIO_QUEUE_SIZE
) {
231 trace_escc_get_queue(CHN_C(s
), val
);
233 serial_receive_byte(s
, 0);
237 static int escc_update_irq_chn(ESCCChannelState
*s
)
239 if ((((s
->wregs
[W_INTR
] & INTR_TXINT
) && (s
->txint
== 1)) ||
240 // tx ints enabled, pending
241 ((((s
->wregs
[W_INTR
] & INTR_RXMODEMSK
) == INTR_RXINT1ST
) ||
242 ((s
->wregs
[W_INTR
] & INTR_RXMODEMSK
) == INTR_RXINTALL
)) &&
243 s
->rxint
== 1) || // rx ints enabled, pending
244 ((s
->wregs
[W_EXTINT
] & EXTINT_BRKINT
) &&
245 (s
->rregs
[R_STATUS
] & STATUS_BRK
)))) { // break int e&p
251 static void escc_update_irq(ESCCChannelState
*s
)
255 irq
= escc_update_irq_chn(s
);
256 irq
|= escc_update_irq_chn(s
->otherchn
);
258 trace_escc_update_irq(irq
);
259 qemu_set_irq(s
->irq
, irq
);
262 static void escc_reset_chn(ESCCChannelState
*s
)
267 for (i
= 0; i
< ESCC_SERIAL_REGS
; i
++) {
271 s
->wregs
[W_TXCTRL1
] = TXCTRL1_1STOP
; // 1X divisor, 1 stop bit, no parity
272 s
->wregs
[W_MINTR
] = MINTR_RST_ALL
;
273 s
->wregs
[W_CLOCK
] = CLOCK_TRXC
; // Synch mode tx clock = TRxC
274 s
->wregs
[W_MISC2
] = MISC2_PLLDIS
; // PLL disabled
275 s
->wregs
[W_EXTINT
] = EXTINT_DCD
| EXTINT_SYNCINT
| EXTINT_CTSINT
|
276 EXTINT_TXUNDRN
| EXTINT_BRKINT
; // Enable most interrupts
278 s
->rregs
[R_STATUS
] = STATUS_TXEMPTY
| STATUS_DCD
| STATUS_SYNC
|
279 STATUS_CTS
| STATUS_TXUNDRN
;
281 s
->rregs
[R_STATUS
] = STATUS_TXEMPTY
| STATUS_TXUNDRN
;
282 s
->rregs
[R_SPEC
] = SPEC_BITS8
| SPEC_ALLSENT
;
285 s
->rxint
= s
->txint
= 0;
286 s
->rxint_under_svc
= s
->txint_under_svc
= 0;
287 s
->e0_mode
= s
->led_mode
= s
->caps_lock_mode
= s
->num_lock_mode
= 0;
291 static void escc_reset(DeviceState
*d
)
293 ESCCState
*s
= ESCC(d
);
295 escc_reset_chn(&s
->chn
[0]);
296 escc_reset_chn(&s
->chn
[1]);
299 static inline void set_rxint(ESCCChannelState
*s
)
302 /* XXX: missing daisy chainnig: escc_chn_b rx should have a lower priority
303 than chn_a rx/tx/special_condition service*/
304 s
->rxint_under_svc
= 1;
305 if (s
->chn
== escc_chn_a
) {
306 s
->rregs
[R_INTR
] |= INTR_RXINTA
;
307 if (s
->wregs
[W_MINTR
] & MINTR_STATUSHI
)
308 s
->otherchn
->rregs
[R_IVEC
] = IVEC_HIRXINTA
;
310 s
->otherchn
->rregs
[R_IVEC
] = IVEC_LORXINTA
;
312 s
->otherchn
->rregs
[R_INTR
] |= INTR_RXINTB
;
313 if (s
->wregs
[W_MINTR
] & MINTR_STATUSHI
)
314 s
->rregs
[R_IVEC
] = IVEC_HIRXINTB
;
316 s
->rregs
[R_IVEC
] = IVEC_LORXINTB
;
321 static inline void set_txint(ESCCChannelState
*s
)
324 if (!s
->rxint_under_svc
) {
325 s
->txint_under_svc
= 1;
326 if (s
->chn
== escc_chn_a
) {
327 if (s
->wregs
[W_INTR
] & INTR_TXINT
) {
328 s
->rregs
[R_INTR
] |= INTR_TXINTA
;
330 if (s
->wregs
[W_MINTR
] & MINTR_STATUSHI
)
331 s
->otherchn
->rregs
[R_IVEC
] = IVEC_HITXINTA
;
333 s
->otherchn
->rregs
[R_IVEC
] = IVEC_LOTXINTA
;
335 s
->rregs
[R_IVEC
] = IVEC_TXINTB
;
336 if (s
->wregs
[W_INTR
] & INTR_TXINT
) {
337 s
->otherchn
->rregs
[R_INTR
] |= INTR_TXINTB
;
344 static inline void clr_rxint(ESCCChannelState
*s
)
347 s
->rxint_under_svc
= 0;
348 if (s
->chn
== escc_chn_a
) {
349 if (s
->wregs
[W_MINTR
] & MINTR_STATUSHI
)
350 s
->otherchn
->rregs
[R_IVEC
] = IVEC_HINOINT
;
352 s
->otherchn
->rregs
[R_IVEC
] = IVEC_LONOINT
;
353 s
->rregs
[R_INTR
] &= ~INTR_RXINTA
;
355 if (s
->wregs
[W_MINTR
] & MINTR_STATUSHI
)
356 s
->rregs
[R_IVEC
] = IVEC_HINOINT
;
358 s
->rregs
[R_IVEC
] = IVEC_LONOINT
;
359 s
->otherchn
->rregs
[R_INTR
] &= ~INTR_RXINTB
;
366 static inline void clr_txint(ESCCChannelState
*s
)
369 s
->txint_under_svc
= 0;
370 if (s
->chn
== escc_chn_a
) {
371 if (s
->wregs
[W_MINTR
] & MINTR_STATUSHI
)
372 s
->otherchn
->rregs
[R_IVEC
] = IVEC_HINOINT
;
374 s
->otherchn
->rregs
[R_IVEC
] = IVEC_LONOINT
;
375 s
->rregs
[R_INTR
] &= ~INTR_TXINTA
;
377 s
->otherchn
->rregs
[R_INTR
] &= ~INTR_TXINTB
;
378 if (s
->wregs
[W_MINTR
] & MINTR_STATUSHI
)
379 s
->rregs
[R_IVEC
] = IVEC_HINOINT
;
381 s
->rregs
[R_IVEC
] = IVEC_LONOINT
;
382 s
->otherchn
->rregs
[R_INTR
] &= ~INTR_TXINTB
;
389 static void escc_update_parameters(ESCCChannelState
*s
)
391 int speed
, parity
, data_bits
, stop_bits
;
392 QEMUSerialSetParams ssp
;
394 if (!qemu_chr_fe_backend_connected(&s
->chr
) || s
->type
!= escc_serial
)
397 if (s
->wregs
[W_TXCTRL1
] & TXCTRL1_PAREN
) {
398 if (s
->wregs
[W_TXCTRL1
] & TXCTRL1_PAREV
)
405 if ((s
->wregs
[W_TXCTRL1
] & TXCTRL1_STPMSK
) == TXCTRL1_2STOP
)
409 switch (s
->wregs
[W_TXCTRL2
] & TXCTRL2_BITMSK
) {
424 speed
= s
->clock
/ ((s
->wregs
[W_BRGLO
] | (s
->wregs
[W_BRGHI
] << 8)) + 2);
425 switch (s
->wregs
[W_TXCTRL1
] & TXCTRL1_CLKMSK
) {
441 ssp
.data_bits
= data_bits
;
442 ssp
.stop_bits
= stop_bits
;
443 trace_escc_update_parameters(CHN_C(s
), speed
, parity
, data_bits
, stop_bits
);
444 qemu_chr_fe_ioctl(&s
->chr
, CHR_IOCTL_SERIAL_SET_PARAMS
, &ssp
);
447 static void escc_mem_write(void *opaque
, hwaddr addr
,
448 uint64_t val
, unsigned size
)
450 ESCCState
*serial
= opaque
;
456 saddr
= (addr
>> reg_shift(serial
)) & 1;
457 channel
= (addr
>> chn_shift(serial
)) & 1;
458 s
= &serial
->chn
[channel
];
461 trace_escc_mem_writeb_ctrl(CHN_C(s
), s
->reg
, val
& 0xff);
465 newreg
= val
& CMD_PTR_MASK
;
475 if (s
->rxint_under_svc
) {
476 s
->rxint_under_svc
= 0;
480 } else if (s
->txint_under_svc
) {
481 s
->txint_under_svc
= 0;
489 case W_INTR
... W_RXCTRL
:
490 case W_SYNC1
... W_TXBUF
:
491 case W_MISC1
... W_CLOCK
:
492 case W_MISC2
... W_EXTINT
:
493 s
->wregs
[s
->reg
] = val
;
497 s
->wregs
[s
->reg
] = val
;
498 escc_update_parameters(s
);
502 s
->wregs
[s
->reg
] = val
;
503 s
->rregs
[s
->reg
] = val
;
504 escc_update_parameters(s
);
507 switch (val
& MINTR_RST_MASK
) {
512 escc_reset_chn(&serial
->chn
[0]);
515 escc_reset_chn(&serial
->chn
[1]);
518 escc_reset(DEVICE(serial
));
531 trace_escc_mem_writeb_data(CHN_C(s
), val
);
533 * Lower the irq when data is written to the Tx buffer and no other
534 * interrupts are currently pending. The irq will be raised again once
535 * the Tx buffer becomes empty below.
540 if (s
->wregs
[W_TXCTRL2
] & TXCTRL2_TXEN
) { // tx enabled
541 if (qemu_chr_fe_backend_connected(&s
->chr
)) {
542 /* XXX this blocks entire thread. Rewrite to use
543 * qemu_chr_fe_write and background I/O callbacks */
544 qemu_chr_fe_write_all(&s
->chr
, &s
->tx
, 1);
545 } else if (s
->type
== escc_kbd
&& !s
->disabled
) {
546 handle_kbd_command(s
, val
);
549 s
->rregs
[R_STATUS
] |= STATUS_TXEMPTY
; // Tx buffer empty
550 s
->rregs
[R_SPEC
] |= SPEC_ALLSENT
; // All sent
558 static uint64_t escc_mem_read(void *opaque
, hwaddr addr
,
561 ESCCState
*serial
= opaque
;
567 saddr
= (addr
>> reg_shift(serial
)) & 1;
568 channel
= (addr
>> chn_shift(serial
)) & 1;
569 s
= &serial
->chn
[channel
];
572 trace_escc_mem_readb_ctrl(CHN_C(s
), s
->reg
, s
->rregs
[s
->reg
]);
573 ret
= s
->rregs
[s
->reg
];
577 s
->rregs
[R_STATUS
] &= ~STATUS_RXAV
;
579 if (s
->type
== escc_kbd
|| s
->type
== escc_mouse
) {
584 trace_escc_mem_readb_data(CHN_C(s
), ret
);
585 qemu_chr_fe_accept_input(&s
->chr
);
593 static const MemoryRegionOps escc_mem_ops
= {
594 .read
= escc_mem_read
,
595 .write
= escc_mem_write
,
596 .endianness
= DEVICE_NATIVE_ENDIAN
,
598 .min_access_size
= 1,
599 .max_access_size
= 1,
603 static int serial_can_receive(void *opaque
)
605 ESCCChannelState
*s
= opaque
;
608 if (((s
->wregs
[W_RXCTRL
] & RXCTRL_RXEN
) == 0) // Rx not enabled
609 || ((s
->rregs
[R_STATUS
] & STATUS_RXAV
) == STATUS_RXAV
))
610 // char already available
617 static void serial_receive_byte(ESCCChannelState
*s
, int ch
)
619 trace_escc_serial_receive_byte(CHN_C(s
), ch
);
620 s
->rregs
[R_STATUS
] |= STATUS_RXAV
;
625 static void serial_receive_break(ESCCChannelState
*s
)
627 s
->rregs
[R_STATUS
] |= STATUS_BRK
;
631 static void serial_receive1(void *opaque
, const uint8_t *buf
, int size
)
633 ESCCChannelState
*s
= opaque
;
634 serial_receive_byte(s
, buf
[0]);
637 static void serial_event(void *opaque
, QEMUChrEvent event
)
639 ESCCChannelState
*s
= opaque
;
640 if (event
== CHR_EVENT_BREAK
)
641 serial_receive_break(s
);
644 static const VMStateDescription vmstate_escc_chn
= {
647 .minimum_version_id
= 1,
648 .fields
= (VMStateField
[]) {
649 VMSTATE_UINT32(vmstate_dummy
, ESCCChannelState
),
650 VMSTATE_UINT32(reg
, ESCCChannelState
),
651 VMSTATE_UINT32(rxint
, ESCCChannelState
),
652 VMSTATE_UINT32(txint
, ESCCChannelState
),
653 VMSTATE_UINT32(rxint_under_svc
, ESCCChannelState
),
654 VMSTATE_UINT32(txint_under_svc
, ESCCChannelState
),
655 VMSTATE_UINT8(rx
, ESCCChannelState
),
656 VMSTATE_UINT8(tx
, ESCCChannelState
),
657 VMSTATE_BUFFER(wregs
, ESCCChannelState
),
658 VMSTATE_BUFFER(rregs
, ESCCChannelState
),
659 VMSTATE_END_OF_LIST()
663 static const VMStateDescription vmstate_escc
= {
666 .minimum_version_id
= 1,
667 .fields
= (VMStateField
[]) {
668 VMSTATE_STRUCT_ARRAY(chn
, ESCCState
, 2, 2, vmstate_escc_chn
,
670 VMSTATE_END_OF_LIST()
674 static void sunkbd_handle_event(DeviceState
*dev
, QemuConsole
*src
,
677 ESCCChannelState
*s
= (ESCCChannelState
*)dev
;
681 assert(evt
->type
== INPUT_EVENT_KIND_KEY
);
682 key
= evt
->u
.key
.data
;
683 qcode
= qemu_input_key_value_to_qcode(key
->key
);
684 trace_escc_sunkbd_event_in(qcode
, QKeyCode_str(qcode
),
687 if (qcode
== Q_KEY_CODE_CAPS_LOCK
) {
689 s
->caps_lock_mode
^= 1;
690 if (s
->caps_lock_mode
== 2) {
691 return; /* Drop second press */
694 s
->caps_lock_mode
^= 2;
695 if (s
->caps_lock_mode
== 3) {
696 return; /* Drop first release */
701 if (qcode
== Q_KEY_CODE_NUM_LOCK
) {
703 s
->num_lock_mode
^= 1;
704 if (s
->num_lock_mode
== 2) {
705 return; /* Drop second press */
708 s
->num_lock_mode
^= 2;
709 if (s
->num_lock_mode
== 3) {
710 return; /* Drop first release */
715 if (qcode
> qemu_input_map_qcode_to_sun_len
) {
719 keycode
= qemu_input_map_qcode_to_sun
[qcode
];
723 trace_escc_sunkbd_event_out(keycode
);
724 put_queue(s
, keycode
);
727 static QemuInputHandler sunkbd_handler
= {
728 .name
= "sun keyboard",
729 .mask
= INPUT_EVENT_MASK_KEY
,
730 .event
= sunkbd_handle_event
,
733 static void handle_kbd_command(ESCCChannelState
*s
, int val
)
735 trace_escc_kbd_command(val
);
736 if (s
->led_mode
) { // Ignore led byte
741 case 1: // Reset, return type code
744 put_queue(s
, 4); // Type 4
747 case 0xe: // Set leds
750 case 7: // Query layout
754 put_queue(s
, 0x21); /* en-us layout */
761 static void sunmouse_event(void *opaque
,
762 int dx
, int dy
, int dz
, int buttons_state
)
764 ESCCChannelState
*s
= opaque
;
767 trace_escc_sunmouse_event(dx
, dy
, buttons_state
);
768 ch
= 0x80 | 0x7; /* protocol start byte, no buttons pressed */
770 if (buttons_state
& MOUSE_EVENT_LBUTTON
)
772 if (buttons_state
& MOUSE_EVENT_MBUTTON
)
774 if (buttons_state
& MOUSE_EVENT_RBUTTON
)
786 put_queue(s
, ch
& 0xff);
795 put_queue(s
, ch
& 0xff);
797 // MSC protocol specify two extra motion bytes
803 static void escc_init1(Object
*obj
)
805 ESCCState
*s
= ESCC(obj
);
806 SysBusDevice
*dev
= SYS_BUS_DEVICE(obj
);
809 for (i
= 0; i
< 2; i
++) {
810 sysbus_init_irq(dev
, &s
->chn
[i
].irq
);
811 s
->chn
[i
].chn
= 1 - i
;
813 s
->chn
[0].otherchn
= &s
->chn
[1];
814 s
->chn
[1].otherchn
= &s
->chn
[0];
816 sysbus_init_mmio(dev
, &s
->mmio
);
819 static void escc_realize(DeviceState
*dev
, Error
**errp
)
821 ESCCState
*s
= ESCC(dev
);
824 s
->chn
[0].disabled
= s
->disabled
;
825 s
->chn
[1].disabled
= s
->disabled
;
827 memory_region_init_io(&s
->mmio
, OBJECT(dev
), &escc_mem_ops
, s
, "escc",
828 ESCC_SIZE
<< s
->it_shift
);
830 for (i
= 0; i
< 2; i
++) {
831 if (qemu_chr_fe_backend_connected(&s
->chn
[i
].chr
)) {
832 s
->chn
[i
].clock
= s
->frequency
/ 2;
833 qemu_chr_fe_set_handlers(&s
->chn
[i
].chr
, serial_can_receive
,
834 serial_receive1
, serial_event
, NULL
,
835 &s
->chn
[i
], NULL
, true);
839 if (s
->chn
[0].type
== escc_mouse
) {
840 qemu_add_mouse_event_handler(sunmouse_event
, &s
->chn
[0], 0,
843 if (s
->chn
[1].type
== escc_kbd
) {
844 s
->chn
[1].hs
= qemu_input_handler_register((DeviceState
*)(&s
->chn
[1]),
849 static Property escc_properties
[] = {
850 DEFINE_PROP_UINT32("frequency", ESCCState
, frequency
, 0),
851 DEFINE_PROP_UINT32("it_shift", ESCCState
, it_shift
, 0),
852 DEFINE_PROP_BOOL("bit_swap", ESCCState
, bit_swap
, false),
853 DEFINE_PROP_UINT32("disabled", ESCCState
, disabled
, 0),
854 DEFINE_PROP_UINT32("chnBtype", ESCCState
, chn
[0].type
, 0),
855 DEFINE_PROP_UINT32("chnAtype", ESCCState
, chn
[1].type
, 0),
856 DEFINE_PROP_CHR("chrB", ESCCState
, chn
[0].chr
),
857 DEFINE_PROP_CHR("chrA", ESCCState
, chn
[1].chr
),
858 DEFINE_PROP_END_OF_LIST(),
861 static void escc_class_init(ObjectClass
*klass
, void *data
)
863 DeviceClass
*dc
= DEVICE_CLASS(klass
);
865 dc
->reset
= escc_reset
;
866 dc
->realize
= escc_realize
;
867 dc
->vmsd
= &vmstate_escc
;
868 device_class_set_props(dc
, escc_properties
);
869 set_bit(DEVICE_CATEGORY_INPUT
, dc
->categories
);
872 static const TypeInfo escc_info
= {
874 .parent
= TYPE_SYS_BUS_DEVICE
,
875 .instance_size
= sizeof(ESCCState
),
876 .instance_init
= escc_init1
,
877 .class_init
= escc_class_init
,
880 static void escc_register_types(void)
882 type_register_static(&escc_info
);
885 type_init(escc_register_types
)