diff options
author | Jörg Frings-Fürst <debian@jff.email> | 2023-02-12 17:35:53 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff.email> | 2023-02-12 17:35:53 +0100 |
commit | 84357741a6a6e6430f199b2c3f7498e0e97da9ad (patch) | |
tree | 23e8d66ede9506b94c76fb36910ca3c7dd15c74e /sanei/sanei_pio.c | |
parent | 302276dc1b90cfc972fb726ca94a23b18f4b0088 (diff) |
New upstream version 1.2.1upstream/1.2.1
Diffstat (limited to 'sanei/sanei_pio.c')
-rw-r--r-- | sanei/sanei_pio.c | 154 |
1 files changed, 10 insertions, 144 deletions
diff --git a/sanei/sanei_pio.c b/sanei/sanei_pio.c index ee27267..cd379dd 100644 --- a/sanei/sanei_pio.c +++ b/sanei/sanei_pio.c @@ -48,6 +48,8 @@ */ #include "../include/sane/config.h" +#include "../include/sane/sanei_directio.h" +/* pick up compatibility defs */ #define BACKEND_NAME sanei_pio #include "../include/sane/sanei_backend.h" /* pick up compatibility defs */ @@ -57,42 +59,10 @@ #endif #include <sys/types.h> -#ifdef HAVE_SYS_IO_H -# include <sys/io.h> /* use where available (glibc 2.x, for example) */ -# ifndef SANE_HAVE_SYS_IO_H_WITH_INB_OUTB -# define IO_SUPPORT_MISSING -# endif -#elif HAVE_ASM_IO_H -# include <asm/io.h> /* ugly, but backwards compatible */ -#elif HAVE_SYS_HW_H -# include <sys/hw.h> -#elif defined(__i386__) && defined (__GNUC__) - -static __inline__ void -outb (u_char value, u_long port) -{ - __asm__ __volatile__ ("outb %0,%1"::"a" (value), "d" ((u_short) port)); -} - -static __inline__ u_char -inb (u_long port) -{ - u_char value; - - __asm__ __volatile__ ("inb %1,%0":"=a" (value):"d" ((u_short) port)); - return value; -} - -#else -# define IO_SUPPORT_MISSING -#endif - #include "../include/sane/sane.h" #include "../include/sane/sanei.h" #include "../include/sane/sanei_pio.h" -#if defined (HAVE_IOPERM) && !defined (IO_SUPPORT_MISSING) - #include <errno.h> #include <fcntl.h> #include <limits.h> @@ -161,8 +131,6 @@ static PortRec port[] = extern int setuid (uid_t); -static inline int pio_outb (const Port port, u_char val, u_long addr); -static inline int pio_inb (const Port port, u_char * val, u_long addr); static inline int pio_wait (const Port port, u_char val, u_char mask); static inline void pio_ctrl (const Port port, u_char val); static inline void pio_delay (const Port port); @@ -173,38 +141,6 @@ static int pio_read (const Port port, u_char * buf, int n); static int pio_open (const char *dev, SANE_Status * status); static inline int -pio_outb (const Port port, u_char val, u_long addr) -{ - - if (-1 == port->fd) - outb (val, addr); - else - { - if (addr != (u_long)lseek (port->fd, addr, SEEK_SET)) - return -1; - if (1 != write (port->fd, &val, 1)) - return -1; - } - return 0; -} - -static inline int -pio_inb (const Port port, u_char * val, u_long addr) -{ - - if (-1 == port->fd) - *val = inb (addr); - else - { - if (addr != (u_long)lseek (port->fd, addr, SEEK_SET)) - return -1; - if (1 != read (port->fd, val, 1)) - return -1; - } - return 0; -} - -static inline int pio_wait (const Port port, u_char val, u_char mask) { int stat = 0; @@ -221,7 +157,7 @@ pio_wait (const Port port, u_char val, u_char mask) for (;;) { ++poll_count; - stat = inb (port->base + PIO_STAT); + stat = sanei_inb (port->base + PIO_STAT); if ((stat & mask) == (val & mask)) { DBG (DL60, "got %02x after %ld tries\n", stat, poll_count); @@ -261,7 +197,7 @@ pio_ctrl (const Port port, u_char val) DBG (DL61, " FDXT %s\n", val & PIO_CTRL_FDXT ? "on" : "off"); DBG (DL61, " NSTROBE %s\n", val & PIO_CTRL_NSTROBE ? "on" : "off"); - outb (val, port->base + PIO_CTRL); + sanei_outb (port->base + PIO_CTRL, val); return; } @@ -269,7 +205,7 @@ pio_ctrl (const Port port, u_char val) static inline void pio_delay (const Port port) { - inb (port->base + PIO_STAT); /* delay */ + sanei_inb (port->base + PIO_STAT); /* delay */ return; } @@ -290,8 +226,8 @@ pio_reset (const Port port) for (n = PIO_APPLYRESET; --n >= 0;) { - outb ((PIO_CTRL_IE | PIO_CTRL_NINIT) ^ PIO_CTRL_NINIT, - port->base + PIO_CTRL); + sanei_outb (port->base + PIO_CTRL, + (PIO_CTRL_IE | PIO_CTRL_NINIT) ^ PIO_CTRL_NINIT); } pio_init (port); @@ -323,7 +259,7 @@ pio_write (const Port port, const u_char * buf, int n) #endif DBG (DL60, "out %02x\n", (int) *buf); - outb (*buf, port->base + PIO_IOPORT); + sanei_outb (port->base + PIO_IOPORT, *buf); pio_delay (port); pio_delay (port); @@ -387,7 +323,7 @@ pio_read (const Port port, u_char * buf, int n) /* busynack */ #endif - *buf = inb (port->base + PIO_IOPORT); + *buf = sanei_inb (port->base + PIO_IOPORT); DBG (DL60, "in %02x\n", (int) *buf); DBG (DL40, "end read byte\n"); } @@ -465,7 +401,7 @@ pio_open (const char *dev, SANE_Status * status) port[n].max_time_seconds = 10; port[n].in_use = 1; - if (ioperm (port[n].base, 3, 1)) + if (sanei_ioperm (port[n].base, 3, 1)) { DBG (1, "sanei_pio_open: cannot get io privilege for port 0x%03lx\n", port[n].base); @@ -533,73 +469,3 @@ sanei_pio_write (int fd, const u_char * buf, int n) return pio_write (&port[fd], buf, n); } - -#else /* !HAVE_IOPERM */ - -#ifdef __BEOS__ - -#include <fcntl.h> - -SANE_Status -sanei_pio_open (const char *dev, int *fdp) -{ - int fp; - - /* open internal parallel port */ - fp=open("/dev/parallel/parallel1",O_RDWR); - - *fdp=fp; - if(fp<0) return SANE_STATUS_INVAL; - return(SANE_STATUS_GOOD); -} - - -void -sanei_pio_close (int fd) -{ - close(fd); - return; -} - -int -sanei_pio_read (int fd, u_char * buf, int n) -{ - return(read(fd,buf,n)); -} - -int -sanei_pio_write (int fd, const u_char * buf, int n) -{ - return(write(fd,buf,n)); -} - -#else /* !__BEOS__ */ - -SANE_Status -sanei_pio_open (const char *dev, int *fdp) -{ - *fdp = -1; - return SANE_STATUS_INVAL; -} - - -void -sanei_pio_close (int fd) -{ - return; -} - -int -sanei_pio_read (int fd, u_char * buf, int n) -{ - return -1; -} - -int -sanei_pio_write (int fd, const u_char * buf, int n) -{ - return -1; -} -#endif /* __BEOS__ */ - -#endif /* !HAVE_IOPERM */ |