sanei: Reuse sanei_directio in sanei_pio

pixma-add-canon-ts-3400-series
Thierry HUCHARD 2021-12-15 22:37:00 +02:00 zatwierdzone przez Povilas Kanapickas
rodzic 7d75dbad0c
commit ab11e42894
2 zmienionych plików z 15 dodań i 43 usunięć

Wyświetl plik

@ -678,6 +678,7 @@ libsane_epson_la_LIBADD = $(COMMON_LIBS) \
../sanei/sanei_usb.lo \ ../sanei/sanei_usb.lo \
../sanei/sanei_scsi.lo \ ../sanei/sanei_scsi.lo \
../sanei/sanei_pio.lo \ ../sanei/sanei_pio.lo \
../sanei/sanei_directio.lo \
$(SCSI_LIBS) $(USB_LIBS) $(RESMGR_LIBS) $(SCSI_LIBS) $(USB_LIBS) $(RESMGR_LIBS)
EXTRA_DIST += epson.conf.in EXTRA_DIST += epson.conf.in
@ -699,6 +700,7 @@ libsane_epson2_la_LIBADD = $(COMMON_LIBS) \
../sanei/sanei_pio.lo \ ../sanei/sanei_pio.lo \
../sanei/sanei_tcp.lo \ ../sanei/sanei_tcp.lo \
../sanei/sanei_udp.lo \ ../sanei/sanei_udp.lo \
../sanei/sanei_directio.lo \
$(SCSI_LIBS) $(USB_LIBS) $(SOCKET_LIBS) $(MATH_LIB) $(RESMGR_LIBS) $(SCSI_LIBS) $(USB_LIBS) $(SOCKET_LIBS) $(MATH_LIB) $(RESMGR_LIBS)
EXTRA_DIST += epson2.conf.in EXTRA_DIST += epson2.conf.in
@ -853,6 +855,7 @@ libsane_hp_la_LIBADD = $(COMMON_LIBS) \
../sanei/sanei_scsi.lo \ ../sanei/sanei_scsi.lo \
../sanei/sanei_pio.lo \ ../sanei/sanei_pio.lo \
../sanei/sanei_thread.lo \ ../sanei/sanei_thread.lo \
../sanei/sanei_directio.lo \
$(SCSI_LIBS) $(USB_LIBS) $(SANEI_THREAD_LIBS) $(RESMGR_LIBS) $(SCSI_LIBS) $(USB_LIBS) $(SANEI_THREAD_LIBS) $(RESMGR_LIBS)
EXTRA_DIST += hp.conf.in EXTRA_DIST += hp.conf.in
# TODO: These should be moved to ../docs/hp; don't belong here. # TODO: These should be moved to ../docs/hp; don't belong here.

Wyświetl plik

@ -48,6 +48,8 @@
*/ */
#include "../include/sane/config.h" #include "../include/sane/config.h"
#include "../include/sane/sanei_directio.h"
/* pick up compatibility defs */
#define BACKEND_NAME sanei_pio #define BACKEND_NAME sanei_pio
#include "../include/sane/sanei_backend.h" /* pick up compatibility defs */ #include "../include/sane/sanei_backend.h" /* pick up compatibility defs */
@ -57,42 +59,10 @@
#endif #endif
#include <sys/types.h> #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/sane.h"
#include "../include/sane/sanei.h" #include "../include/sane/sanei.h"
#include "../include/sane/sanei_pio.h" #include "../include/sane/sanei_pio.h"
#if defined (HAVE_IOPERM) && !defined (IO_SUPPORT_MISSING)
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <limits.h> #include <limits.h>
@ -177,7 +147,7 @@ pio_outb (const Port port, u_char val, u_long addr)
{ {
if (-1 == port->fd) if (-1 == port->fd)
outb (val, addr); sanei_outb (addr, val);
else else
{ {
if (addr != (u_long)lseek (port->fd, addr, SEEK_SET)) if (addr != (u_long)lseek (port->fd, addr, SEEK_SET))
@ -193,7 +163,7 @@ pio_inb (const Port port, u_char * val, u_long addr)
{ {
if (-1 == port->fd) if (-1 == port->fd)
*val = inb (addr); *val = sanei_inb (addr);
else else
{ {
if (addr != (u_long)lseek (port->fd, addr, SEEK_SET)) if (addr != (u_long)lseek (port->fd, addr, SEEK_SET))
@ -221,7 +191,7 @@ pio_wait (const Port port, u_char val, u_char mask)
for (;;) for (;;)
{ {
++poll_count; ++poll_count;
stat = inb (port->base + PIO_STAT); stat = sanei_inb (port->base + PIO_STAT);
if ((stat & mask) == (val & mask)) if ((stat & mask) == (val & mask))
{ {
DBG (DL60, "got %02x after %ld tries\n", stat, poll_count); DBG (DL60, "got %02x after %ld tries\n", stat, poll_count);
@ -261,7 +231,7 @@ pio_ctrl (const Port port, u_char val)
DBG (DL61, " FDXT %s\n", val & PIO_CTRL_FDXT ? "on" : "off"); DBG (DL61, " FDXT %s\n", val & PIO_CTRL_FDXT ? "on" : "off");
DBG (DL61, " NSTROBE %s\n", val & PIO_CTRL_NSTROBE ? "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; return;
} }
@ -269,7 +239,7 @@ pio_ctrl (const Port port, u_char val)
static inline void static inline void
pio_delay (const Port port) pio_delay (const Port port)
{ {
inb (port->base + PIO_STAT); /* delay */ sanei_inb (port->base + PIO_STAT); /* delay */
return; return;
} }
@ -290,8 +260,8 @@ pio_reset (const Port port)
for (n = PIO_APPLYRESET; --n >= 0;) for (n = PIO_APPLYRESET; --n >= 0;)
{ {
outb ((PIO_CTRL_IE | PIO_CTRL_NINIT) ^ PIO_CTRL_NINIT, sanei_outb (port->base + PIO_CTRL,
port->base + PIO_CTRL); (PIO_CTRL_IE | PIO_CTRL_NINIT) ^ PIO_CTRL_NINIT);
} }
pio_init (port); pio_init (port);
@ -323,7 +293,7 @@ pio_write (const Port port, const u_char * buf, int n)
#endif #endif
DBG (DL60, "out %02x\n", (int) *buf); 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);
pio_delay (port); pio_delay (port);
@ -387,7 +357,7 @@ pio_read (const Port port, u_char * buf, int n)
/* busynack */ /* busynack */
#endif #endif
*buf = inb (port->base + PIO_IOPORT); *buf = sanei_inb (port->base + PIO_IOPORT);
DBG (DL60, "in %02x\n", (int) *buf); DBG (DL60, "in %02x\n", (int) *buf);
DBG (DL40, "end read byte\n"); DBG (DL40, "end read byte\n");
} }
@ -465,7 +435,7 @@ pio_open (const char *dev, SANE_Status * status)
port[n].max_time_seconds = 10; port[n].max_time_seconds = 10;
port[n].in_use = 1; 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", DBG (1, "sanei_pio_open: cannot get io privilege for port 0x%03lx\n",
port[n].base); port[n].base);
@ -533,4 +503,3 @@ sanei_pio_write (int fd, const u_char * buf, int n)
return pio_write (&port[fd], buf, n); return pio_write (&port[fd], buf, n);
} }
#endif /* !HAVE_IOPERM */