Skip to contentSkip to conversation

Parallel Port Direction Fix

PATCH Applied Vijay Kumar 2 participants 2 messages Jun 10, 2008 – Aug 22, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Parallel Port Direction Fix

The direction bit in the control register should not be directly set using PPWCONTROL. The kernel gives the following debug message.

parport0 (ppdev0): use data_reverse for this!

More over setting the data pins to forward mode does not work, perhaps a bug in the Linux PP driver. The right way to do this is to use PPDATADIR to set the direction. The patch checks if the user is toggling the direction bit, and invokes PPDATADIR to do the job.

---

hw/parallel.c +0 -0
diff -Naur qemu-orig/hw/parallel.c qemu-mod/hw/parallel.c
@@ -129,6 +129,7 @@
{
    ParallelState *s = opaque;
    uint8_t parm = val;

+ int dir;

/* Sometimes programs do several writes for timing purposes on old
HW. Take care not to waste time on writes that do nothing. */
@@ -154,6 +155,17 @@

        if (s->control == val)
            return;
        pdebug("wc%02x\n", val);

+
+ if ((val & PARA_CTR_DIR) != (s->control & PARA_CTR_DIR)) {
+ if (val & PARA_CTR_DIR) {
+ dir = 1;
+ } else {
+ dir = 0;

+            }
+            qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_DATA_DIR, &dir);
+            parm &= ~PARA_CTR_DIR;
+        }
+
        qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_WRITE_CONTROL, &parm);
        s->control = val;
        break;
qemu-char.h +0 -0
diff -Naur qemu-orig/qemu-char.h qemu-mod/qemu-char.h
@@ -27,6 +27,7 @@

#define CHR_IOCTL_PP_EPP_READ 9
#define CHR_IOCTL_PP_EPP_WRITE_ADDR 10
#define CHR_IOCTL_PP_EPP_WRITE 11
+#define CHR_IOCTL_PP_DATA_DIR 12

typedef void IOEventHandler(void *opaque, int event);

vl.c +4 -0
diff -Naur qemu-orig/vl.c qemu-mod/vl.c
@@ -2525,6 +2525,10 @@
            return -ENOTSUP;
        *(uint8_t *)arg = b;
        break;
+    case CHR_IOCTL_PP_DATA_DIR:
+        if (ioctl(fd, PPDATADIR, (int *)arg) < 0)
+            return -ENOTSUP;
+        break;
    case CHR_IOCTL_PP_EPP_READ_ADDR:
	if (pp_hw_mode(drv, IEEE1284_MODE_EPP|IEEE1284_ADDR)) {
	    struct ParallelIOArg *parg = arg;
#1 lore raw
Quoted 10 lines · Vijay Kumar

The direction bit in the control register should not be directly set using PPWCONTROL. The kernel gives the following debug message.

parport0 (ppdev0): use data_reverse for this!

More over setting the data pins to forward mode does not work, perhaps a bug in the Linux PP driver. The right way to do this is to use PPDATADIR to set the direction. The patch checks if the user is toggling the direction bit, and invokes PPDATADIR to do the job.

Applied, thanks.

Quoted 59 lines

---
diff -Naur qemu-orig/hw/parallel.c qemu-mod/hw/parallel.c

hw/parallel.c +12 -0
@@ -129,6 +129,7 @@
 {
    ParallelState *s = opaque;
    uint8_t parm = val;
+    int dir;
 
    /* Sometimes programs do several writes for timing purposes on old
       HW. Take care not to waste time on writes that do nothing. */
@@ -154,6 +155,17 @@
        if (s->control == val)
            return;
        pdebug("wc%02x\n", val);
+
+        if ((val & PARA_CTR_DIR) != (s->control & PARA_CTR_DIR)) {
+            if (val & PARA_CTR_DIR) {
+                dir = 1;
+            } else {
+                dir = 0;
+            }
+            qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_DATA_DIR, &dir);
+            parm &= ~PARA_CTR_DIR;
+        }
+
        qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_WRITE_CONTROL, &parm);
        s->control = val;
        break;

diff -Naur qemu-orig/qemu-char.h qemu-mod/qemu-char.h

qemu-char.h +1 -0
@@ -27,6 +27,7 @@
 #define CHR_IOCTL_PP_EPP_READ         9
 #define CHR_IOCTL_PP_EPP_WRITE_ADDR  10
 #define CHR_IOCTL_PP_EPP_WRITE       11
+#define CHR_IOCTL_PP_DATA_DIR        12
 
 typedef void IOEventHandler(void *opaque, int event);
 

diff -Naur qemu-orig/vl.c qemu-mod/vl.c

vl.c +4 -0
@@ -2525,6 +2525,10 @@
            return -ENOTSUP;
        *(uint8_t *)arg = b;
        break;
+    case CHR_IOCTL_PP_DATA_DIR:
+        if (ioctl(fd, PPDATADIR, (int *)arg) < 0)
+            return -ENOTSUP;
+        break;
    case CHR_IOCTL_PP_EPP_READ_ADDR:
 	if (pp_hw_mode(drv, IEEE1284_MODE_EPP|IEEE1284_ADDR)) {
 	    struct ParallelIOArg *parg = arg;
Signature · 4 lines
  .''`.  Aurelien Jarno	            | GPG: 1024D/F1BCDB73
 : :' :  Debian developer           | Electrical Engineer
 `. `'   [email protected]         | [email protected]
   `-    people.debian.org/~aurel32 | www.aurel32.net