qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Shin-ichiro KAWASAKI <kawasaki@juno.dti.ne.jp>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 3/3] sh: SCI improvements
Date: Sun, 11 Jan 2009 18:16:32 +0900	[thread overview]
Message-ID: <4969B8F0.4020104@juno.dti.ne.jp> (raw)

SE7750 uses SCI := Serial Communication Interface for one of consoles.
This patch completes the SCI implementation, and makes SCI available
for a console.

# Tabs and spaces are mixed in "hw/sh_serial.c" so much.
# Some clean up might be useful.


Signed-off-by: Shin-ichiro KAWASAKI <kawasaki@juno.dti.ne.jp>

Index: trunk/hw/sh_serial.c
===================================================================
--- trunk/hw/sh_serial.c	(revision 6133)
+++ trunk/hw/sh_serial.c	(working copy)
@@ -96,7 +96,7 @@
         s->scr = val & ((s->feat & SH_SERIAL_FEAT_SCIF) ? 0xfa : 0xff);
         if (!(val & (1 << 5)))
             s->flags |= SH_SERIAL_FLAG_TEND;
-        if ((s->feat & SH_SERIAL_FEAT_SCIF) && s->txi) {
+        if (s->txi) {
 	    qemu_set_irq(s->txi, val & (1 << 7));
         }
         if (!(val & (1 << 6))) {
@@ -109,13 +109,15 @@
             qemu_chr_write(s->chr, &ch, 1);
 	}
 	s->dr = val;
-	s->flags &= ~SH_SERIAL_FLAG_TDE;
+        if (s->feat & SH_SERIAL_FEAT_SCIF)
+            s->flags &= ~SH_SERIAL_FLAG_TDE;
+        else
+            s->flags |= SH_SERIAL_FLAG_TDE;
         return;
-#if 0
     case 0x14: /* FRDR / RDR */
-        ret = 0;
+        /* do nothing */
+        return;
         break;
-#endif
     }
     if (s->feat & SH_SERIAL_FEAT_SCIF) {
         switch(offs) {
@@ -165,17 +167,33 @@
         case 0x24: /* LSR */
             return;
         }
-    }
-    else {
+    } else { /* SCI */
         switch(offs) {
-#if 0
-        case 0x0c:
-            ret = s->dr;
-            break;
-        case 0x10:
-            ret = 0;
-            break;
-#endif
+        case 0x0c: /* TDR */
+            if (s->chr) {
+                ch = val;
+                qemu_chr_write(s->chr, &ch, 1);
+            }
+            s->dr = val;
+            s->flags |= SH_SERIAL_FLAG_TDE | SH_SERIAL_FLAG_TEND;
+            if (s->scr & (1 << 7) && s->txi) {
+                qemu_set_irq(s->txi, 1);
+            }
+            return;
+        case 0x10: /* SSR */
+            /*
+             * Ignore TDRE (1 << 7) bit because TDR is always
+             * writable in this SCI emulation.
+             */
+            if (!(val & (1 << 6))) {
+                s->flags &= ~SH_SERIAL_FLAG_RDF;
+            }
+            if (!(val & (1 << 6))) {
+                if (s->rxi) {
+                    qemu_set_irq(s->rxi, 0);
+                }
+            }
+            return;
         case 0x1c:
             s->sptr = val & 0x8f;
             return;
@@ -191,30 +209,19 @@
     sh_serial_state *s = opaque;
     uint32_t ret = ~0;
 
-#if 0
     switch(offs) {
-    case 0x00:
+    case 0x00: /* SMR */
         ret = s->smr;
         break;
-    case 0x04:
+    case 0x04: /* BRR */
         ret = s->brr;
 	break;
-    case 0x08:
+    case 0x08: /* SCR */
         ret = s->scr;
         break;
-    case 0x14:
-        ret = 0;
-        break;
     }
-#endif
     if (s->feat & SH_SERIAL_FEAT_SCIF) {
         switch(offs) {
-        case 0x00: /* SMR */
-            ret = s->smr;
-            break;
-        case 0x08: /* SCR */
-            ret = s->scr;
-            break;
         case 0x10: /* FSR */
             ret = 0;
             if (s->flags & SH_SERIAL_FLAG_TEND)
@@ -242,11 +249,9 @@
                     s->flags &= ~SH_SERIAL_FLAG_RDF;
             }
             break;
-#if 0
         case 0x18:
             ret = s->fcr;
             break;
-#endif
         case 0x1c:
             ret = s->rx_cnt;
             break;
@@ -257,21 +262,26 @@
             ret = 0;
             break;
         }
-    }
-    else {
+    } else {
         switch(offs) {
-#if 0
-        case 0x0c:
+        case 0x0c: /* TDR */
             ret = s->dr;
             break;
-        case 0x10:
+        case 0x10: /* SSR */
             ret = 0;
+            if (s->flags & SH_SERIAL_FLAG_TDE)
+                ret |= (1 << 7);
+            if (s->flags & SH_SERIAL_FLAG_RDF)
+                ret |= (1 << 6);
+            if (s->flags & SH_SERIAL_FLAG_TEND)
+                ret |= (1 << 2);
+            /* TODO : handle bit MPBT */
             break;
-        case 0x14:
+        case 0x14: /* RDR */
             ret = s->rx_fifo[0];
+            s->flags &= ~SH_SERIAL_FLAG_RDF;
             break;
-#endif
-        case 0x1c:
+        case 0x1c: /* SPTR */
             ret = s->sptr;
             break;
         }
@@ -311,6 +321,10 @@
         }
     } else {
         s->rx_fifo[0] = ch;
+        s->flags |= SH_SERIAL_FLAG_RDF;
+        if (s->scr & (1 << 6) && s->rxi) {
+            qemu_set_irq(s->rxi, 1);
+        }
     }
 }
 

         reply	other threads:[~2009-01-11  9:16 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-11  9:14 [Qemu-devel] [PATCH 2/3] sh: movca.l cancel by ocbi Shin-ichiro KAWASAKI
2009-01-11  9:16 ` Shin-ichiro KAWASAKI [this message]
2009-01-11 15:30   ` [Qemu-devel] [PATCH 3/3] sh: SCI improvements Jean-Christophe PLAGNIOL-VILLARD
2009-01-11 17:02   ` [Qemu-devel] [PATCH] sh/serial: allow cpu regs definition Jean-Christophe PLAGNIOL-VILLARD
2009-01-12  6:42   ` [Qemu-devel] [PATCH 3/3] sh: SCI improvements Jean-Christophe PLAGNIOL-VILLARD
2009-01-11 14:22 ` [Qemu-devel] [PATCH 2/3] sh: movca.l cancel by ocbi Edgar E. Iglesias
2009-01-12  5:13   ` Shin-ichiro KAWASAKI
2009-01-13  0:21     ` Shin-ichiro KAWASAKI
2009-01-14 18:46       ` Edgar E. Iglesias

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4969B8F0.4020104@juno.dti.ne.jp \
    --to=kawasaki@juno.dti.ne.jp \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).