diff mbox

[1/3] Improve grlib-apbuart

Message ID 1361274307-5731-2-git-send-email-chouteau@adacore.com
State New
Headers show

Commit Message

Fabien Chouteau Feb. 19, 2013, 11:45 a.m. UTC
From: Ronald Hecht <ronald.hecht@gmx.de>

From: Ronald Hecht <ronald.hecht@gmx.de>

Signed-off-by: Fabien Chouteau <chouteau@adacore.com>
---
 hw/grlib_apbuart.c |   52 +++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 37 insertions(+), 15 deletions(-)

Comments

Andreas Färber Feb. 19, 2013, 1:26 p.m. UTC | #1
Am 19.02.2013 12:45, schrieb Fabien Chouteau:
> From: Ronald Hecht <ronald.hecht@gmx.de>
> 
> From: Ronald Hecht <ronald.hecht@gmx.de>
> 
> Signed-off-by: Fabien Chouteau <chouteau@adacore.com>

Duplicate From header and no proper commit message.
The patch is doing too many things at once: Renaming gptimer ->apbuart
should go into its own patch for instance and not be mixed with adding
reset support and whatever functional UART changes.

Regards,
Andreas
Fabien Chouteau Feb. 19, 2013, 2:41 p.m. UTC | #2
On 02/19/2013 02:26 PM, Andreas Färber wrote:
> Am 19.02.2013 12:45, schrieb Fabien Chouteau:
>> From: Ronald Hecht <ronald.hecht@gmx.de>
>>
>> From: Ronald Hecht <ronald.hecht@gmx.de>
>>
>> Signed-off-by: Fabien Chouteau <chouteau@adacore.com>
> 
> Duplicate From header and no proper commit message.
> The patch is doing too many things at once: Renaming gptimer ->apbuart
> should go into its own patch for instance and not be mixed with adding
> reset support and whatever functional UART changes.
> 

OK, I will rewrite them.


Regards,
diff mbox

Patch

diff --git a/hw/grlib_apbuart.c b/hw/grlib_apbuart.c
index 760bed0..ba1685a 100644
--- a/hw/grlib_apbuart.c
+++ b/hw/grlib_apbuart.c
@@ -75,7 +75,6 @@  typedef struct UART {
     CharDriverState *chr;
 
     /* registers */
-    uint32_t receive;
     uint32_t status;
     uint32_t control;
 
@@ -136,12 +135,14 @@  static void grlib_apbuart_receive(void *opaque, const uint8_t *buf, int size)
 {
     UART *uart = opaque;
 
-    uart_add_to_fifo(uart, buf, size);
+    if (uart->control & UART_RECEIVE_ENABLE) {
+        uart_add_to_fifo(uart, buf, size);
 
-    uart->status |= UART_DATA_READY;
+        uart->status |= UART_DATA_READY;
 
-    if (uart->control & UART_RECEIVE_INTERRUPT) {
-        qemu_irq_pulse(uart->irq);
+        if (uart->control & UART_RECEIVE_INTERRUPT) {
+            qemu_irq_pulse(uart->irq);
+        }
     }
 }
 
@@ -193,8 +194,15 @@  static void grlib_apbuart_write(void *opaque, hwaddr addr,
     switch (addr) {
     case DATA_OFFSET:
     case DATA_OFFSET + 3:       /* When only one byte write */
-        c = value & 0xFF;
-        qemu_chr_fe_write(uart->chr, &c, 1);
+        /* Transmit when character device available and transmitter enabled */
+        if ((uart->chr) && (uart->control & UART_TRANSMIT_ENABLE)) {
+            c = value & 0xFF;
+            qemu_chr_fe_write(uart->chr, &c, 1);
+            /* Generate interrupt */
+            if (uart->control & UART_TRANSMIT_INTERRUPT) {
+                qemu_irq_pulse(uart->irq);
+            }
+        }
         return;
 
     case STATUS_OFFSET:
@@ -242,30 +250,44 @@  static int grlib_apbuart_init(SysBusDevice *dev)
     return 0;
 }
 
-static Property grlib_gptimer_properties[] = {
+static void grlib_apbuart_reset(DeviceState *d)
+{
+    UART *uart = container_of(d, UART, busdev.qdev);
+
+    /* Transmitter FIFO and shift registers are always empty in QEMU */
+    uart->status =  UART_TRANSMIT_FIFO_EMPTY | UART_TRANSMIT_SHIFT_EMPTY;
+    /* Everything is off */
+    uart->control = 0;
+    /* Flush receive FIFO */
+    uart->len = 0;
+    uart->current = 0;
+}
+
+static Property grlib_apbuart_properties[] = {
     DEFINE_PROP_CHR("chrdev", UART, chr),
     DEFINE_PROP_END_OF_LIST(),
 };
 
-static void grlib_gptimer_class_init(ObjectClass *klass, void *data)
+static void grlib_apbuart_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
     SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
     k->init = grlib_apbuart_init;
-    dc->props = grlib_gptimer_properties;
+    dc->reset = grlib_apbuart_reset;
+    dc->props = grlib_apbuart_properties;
 }
 
-static const TypeInfo grlib_gptimer_info = {
+static const TypeInfo grlib_apbuart_info = {
     .name          = "grlib,apbuart",
     .parent        = TYPE_SYS_BUS_DEVICE,
     .instance_size = sizeof(UART),
-    .class_init    = grlib_gptimer_class_init,
+    .class_init    = grlib_apbuart_class_init,
 };
 
-static void grlib_gptimer_register_types(void)
+static void grlib_apbuart_register_types(void)
 {
-    type_register_static(&grlib_gptimer_info);
+    type_register_static(&grlib_apbuart_info);
 }
 
-type_init(grlib_gptimer_register_types)
+type_init(grlib_apbuart_register_types)