Made usage of the new sanei_pp functions, made EPP modes work with libieee1284.

Also did some cleanup work.
merge-requests/1/head
Gerhard Jaeger 2003-10-29 16:53:18 +00:00
rodzic 8d468ca0e5
commit ed3b457ccc
8 zmienionych plików z 146 dodań i 120 usunięć

Wyświetl plik

@ -75,13 +75,14 @@
/*************************** local functions *********************************/
/*.............................................................................
* as the name says...
/** as the name says...
*/
static void detectResetPort( pScanData ps )
{
UChar control;
DBG( DBG_HIGH, "ResetPort()\n" );
control = _INB_CTRL( ps );
_DO_UDELAY( 2 );
@ -92,9 +93,8 @@ static void detectResetPort( pScanData ps )
_DO_UDELAY( 2 );
}
/*.............................................................................
* Check will the status port changed between printer/scanner path changed?
* Write out data and read in to compare
/** Check: will the status port changed between printer/scanner path changed?
* Write out data and read in to compare
*/
static int detectScannerConnection( pScanData ps )
{
@ -205,15 +205,13 @@ static int detectScannerConnection( pScanData ps )
return retval;
}
/*.............................................................................
* we need some memory...
/** we need some memory...
*/
static int detectSetupBuffers( pScanData ps )
{
DBG( DBG_LOW, "*** setupBuffers ***\n" );
/*
* bad news ?
/* bad news ?
*/
if ( 0 == ps->TotalBufferRequire ) {
@ -325,8 +323,7 @@ static int detectSetupBuffers( pScanData ps )
return _OK;
}
/*.............................................................................
* model 48xx detection or any other model using the 96001/3 ASIC
/** model 48xx detection or any other model using the 96001/3 ASIC
*/
static int detectP48xx( pScanData ps )
{
@ -346,8 +343,7 @@ static int detectP48xx( pScanData ps )
return detectScannerConnection( ps );
}
/*.............................................................................
* ASIC 98003 model detection
/** ASIC 98003 model detection
*/
static int detectAsic98003( pScanData ps )
{
@ -369,8 +365,7 @@ static int detectAsic98003( pScanData ps )
return detectScannerConnection( ps );
}
/*.............................................................................
* ASIC 98001 model detection
/** ASIC 98001 model detection
*/
static int detectAsic98001( pScanData ps )
{
@ -404,8 +399,7 @@ static int detectAsic98001( pScanData ps )
/************************ exported functions *********************************/
/*.............................................................................
* here we try to find the scanner, depending on the mode
/** here we try to find the scanner, depending on the mode
*/
_LOC int DetectScanner( pScanData ps, int mode )
{
@ -422,15 +416,13 @@ _LOC int DetectScanner( pScanData ps, int mode )
return _E_INTERNAL;
}
/*
* autodetection ?
/* autodetection ?
*/
if( 0 == mode ) {
DBG( DBG_HIGH, "Starting Scanner-Autodetection\n" );
/*
* try to find a 48xx Scanner
/* try to find a 48xx Scanner
* (or even a scanner based on the 96001/3) ASIC
*/
result = detectP48xx( ps );
@ -439,8 +431,7 @@ _LOC int DetectScanner( pScanData ps, int mode )
DBG( DBG_LOW, "************* ASIC9800x *************\n" );
/*
* get the ASIC ID by using the OpenScanPath stuff from Asic9600x based
/* get the ASIC ID by using the OpenScanPath stuff from Asic9600x based
* models - only difference: change the ReadHigh/ReadLow signals before
*/
ps->CtrlReadHighNibble = _CTRL_GENSIGNAL+_CTRL_AUTOLF+_CTRL_STROBE;

Wyświetl plik

@ -211,7 +211,6 @@
#define _CTRL_END_DATAWRITE (_CTRL_GENSIGNAL) /* 0xc4 */
#define _CTRL_EPPSIGNAL_WRITE (_CTRL_GENSIGNAL + _CTRL_STROBE) /* 0xc5 */
#define _CTRL_EPPTRIG_REGWRITE (_CTRL_GENSIGNAL + _CTRL_SELECT_IN + _CTRL_STROBE)
#define _CTRL_EPPTRIG_DATAWRITE (_CTRL_GENSIGNAL + _CTRL_AUTOLF + _CTRL_STROBE)
#define _CTRL_END_DATAREAD (_CTRL_GENSIGNAL) /* 0xc4 */
#define _CTRL_SIGNAL_BIDIREAD (_CTRL_GENSIGNAL + _CTRL_DIRECTION + _CTRL_AUTOLF)

Wyświetl plik

@ -216,8 +216,7 @@ static UChar ioDataFromSPPSlowest( pScanData ps )
return bData;
}
/*.............................................................................
* Using buffer I/O to read data from EPP Data Port
/** Using buffered I/O to read data from EPP Data Port
*/
static Bool fnEPPRead( pScanData ps, pUChar pBuffer, ULong ulSize )
{
@ -225,15 +224,31 @@ static Bool fnEPPRead( pScanData ps, pUChar pBuffer, ULong ulSize )
if( _IS_ASIC98(ps->sCaps.AsicID)) {
#ifndef __KERNEL__
if( sanei_pp_uses_directio()) {
_OUTB_CTRL( ps, (_CTRL_GENSIGNAL + _CTRL_DIRECTION));
_DO_UDELAY( 1 );
} else {
sanei_pp_set_datadir( ps->pardev, SANEI_PP_DATAIN );
}
#else
_OUTB_CTRL( ps, (_CTRL_GENSIGNAL + _CTRL_DIRECTION));
_DO_UDELAY( 1 );
_DO_UDELAY( 1 );
#endif
for( i = 0; i < ulSize; i++ )
pBuffer[i] = _INB_EPPDATA( ps );
_OUTB_CTRL( ps, _CTRL_GENSIGNAL );
_DO_UDELAY( 1 );
#ifndef __KERNEL__
if( sanei_pp_uses_directio()) {
_OUTB_CTRL( ps, _CTRL_GENSIGNAL );
_DO_UDELAY( 1 );
} else {
sanei_pp_set_datadir( ps->pardev, SANEI_PP_DATAOUT );
}
#else
_OUTB_CTRL( ps, _CTRL_GENSIGNAL );
_DO_UDELAY( 1 );
#endif
} else {
for( i = 0; i < ulSize; i++ )
@ -616,8 +631,7 @@ static void ioSPPWrite( pScanData ps, pUChar pBuffer, ULong size )
DBG( DBG_IO , "... done.\n" );
}
/*.............................................................................
*
/** set the scanner to "read" data mode
*/
static void ioEnterReadMode( pScanData ps )
{
@ -930,29 +944,28 @@ _LOC void IOSoftwareReset( pScanData ps )
ps->CloseScanPath( ps );
}
/*.............................................................................
* Read specific length data from scanner and the method depends on the
* mode defined in registry.
/** Read specific length data from scanner and the method depends on the
* mode defined in registry.
*/
_LOC void IOReadScannerImageData( pScanData ps, pUChar pBuf, ULong size )
{
if( _ASIC_IS_98003 != ps->sCaps.AsicID )
ps->OpenScanPath( ps);
if( _ASIC_IS_98003 != ps->sCaps.AsicID )
ps->OpenScanPath( ps);
if( _IS_ASIC98( ps->sCaps.AsicID))
IODataToRegister(ps, ps->RegModeControl, ps->AsicReg.RD_ModeControl );
if( _IS_ASIC98( ps->sCaps.AsicID))
IODataToRegister( ps, ps->RegModeControl, ps->AsicReg.RD_ModeControl );
/* enter read mode */
ioEnterReadMode( ps );
/* enter read mode */
ioEnterReadMode( ps );
/* call corresponding read proc */
ps->Device.ReadData( ps, pBuf, size );
ps->Device.ReadData( ps, pBuf, size );
/* Clear EPP/ECP read mode by simplely close scanner path and re-open it */
ps->CloseScanPath( ps );
/* Clear EPP/ECP read mode by simply close scanner path and re-open it */
ps->CloseScanPath( ps );
if( _ASIC_IS_98003 == ps->sCaps.AsicID )
ps->OpenScanPath( ps );
if( _ASIC_IS_98003 == ps->sCaps.AsicID )
ps->OpenScanPath( ps );
}
#ifdef __KERNEL__

Wyświetl plik

@ -109,13 +109,13 @@
/*************************** some local vars *********************************/
static int port_feature;
static long randomnum = 1;
static int port_feature = 0;
static long randomnum = 1;
#ifdef __KERNEL__
static int portIsClaimed[_MAX_PTDEVS] = { [0 ... (_MAX_PTDEVS-1)] = 0 };
MODELSTR; /* is a static char array (see plustek-share.h) */
MODELSTR; /**< a static char array (see plustek-pp.h) */
#else
static int portIsClaimed[_MAX_PTDEVS] = { 0, 0, 0, 0 };
@ -269,28 +269,29 @@ static int miscSetFastMode( pScanData ps )
} else {
DBG(DBG_LOW, "Port could not be set to (ECP) PS2 mode. "
"Using SPP mode.\n");
_OUTB_ECTL(ps,ps->IO.lastPortMode); /* restore */
a = ps->IO.lastPortMode & 0x1F;
_OUTB_ECTL(ps, a); /* set ECP ctrl to SPP */
_DO_UDELAY(1);
ps->IO.portMode = _PORT_SPP;
/* next mode, last attempt... */
}
}
}
/*
* Some BIOS/cards have only a Bi-directional/PS2 mode (no EPP).
* Make one last attemp to set to PS2 mode.
*/
if ( port_feature & PARPORT_MODE_PCPS2 ){
if ( port_feature & PARPORT_MODE_PCPS2 ){
DBG(DBG_LOW, "Attempting to set PS2 mode.\n" );
DBG(DBG_LOW, "Attempting to set PS2 mode.\n" );
a = _INB_CTRL(ps); /* get current setting of control register*/
a = _INB_CTRL(ps); /* get current setting of control register*/
ps->IO.lastPortMode = a; /* save it for restoring later */
a = a | 0x20; /* set bit 5 of control reg */
a = a | 0x20; /* set bit 5 of control reg */
_OUTB_CTRL(ps,a); /* set to Fast Centronics/bi-directional/PS2 */
_DO_UDELAY(1);
a = 0;
a = 0;
_OUTB_DATA(ps,0x55);
_DO_UDELAY(1);
@ -303,23 +304,22 @@ static int miscSetFastMode( pScanData ps )
if (_INB_DATA(ps) != 0xAA) /* read data */
a++;
if (2 == a) {
DBG(DBG_LOW, "Port is set to PS2 bidirectional mode.\n");
ps->IO.portMode = _PORT_BIDI;
if( 2 == a ) {
DBG(DBG_LOW, "Port is set to PS2 bidirectional mode.\n");
ps->IO.portMode = _PORT_BIDI;
return _OK;
}
else {
DBG(DBG_LOW, "Port could not be set to PS2 mode. "
} else {
DBG(DBG_LOW, "Port could not be set to PS2 mode. "
"Using SPP mode.\n");
_OUTB_CTRL(ps,(Byte)ps->IO.lastPortMode); /* restore */
_DO_UDELAY(1);
ps->IO.portMode = _PORT_SPP;
}
}
ps->IO.portMode = _PORT_SPP;
}
}
/*
* reaching this point, we're back in SPP mode and there's no need
* to restore at shutdown...
/* reaching this point, we're back in SPP mode and there's no need
* to restore at shutdown...
*/
ps->IO.lastPortMode = 0xFFFF;
@ -499,37 +499,40 @@ _LOC int MiscInitPorts( pScanData ps, int port )
if( NULL == ps )
return _E_NULLPTR;
if( SANE_STATUS_GOOD != sanei_pp_getmode( ps->pardev, &mode )) {
if( SANE_STATUS_GOOD != sanei_pp_getmodes( ps->pardev, &mode )) {
DBG(DBG_HIGH, "Cannot get port mode!\n" );
return _E_NO_PORT;
}
if( mode & SANEI_PP_MODE_SPP ) {
DBG(DBG_LOW, "Setting SPP-mode\n" );
DBG( DBG_LOW, "Setting SPP-mode\n" );
ps->IO.portMode = _PORT_SPP;
}
if( mode & SANEI_PP_MODE_BIDI ) {
DBG(DBG_LOW, "Setting PS/2-mode\n" );
DBG( DBG_LOW, "Setting PS/2-mode\n" );
ps->IO.portMode = _PORT_BIDI;
}
if( mode & SANEI_PP_MODE_EPP ) {
DBG(DBG_LOW, "Setting EPP-mode\n" );
DBG( DBG_LOW, "Setting EPP-mode\n" );
ps->IO.portMode = _PORT_EPP;
}
if( mode & SANEI_PP_MODE_ECP ) {
DBG(DBG_HIGH, "ECP detected --> not supported\n" );
DBG( DBG_HIGH, "ECP detected --> not supported\n" );
return _E_NOSUPP;
}
DBG(DBG_HIGH, "SPP mode used (WORKAROUND)!!!\n" );
ps->IO.portMode = _PORT_SPP;
if( sanei_pp_uses_directio()) {
DBG( DBG_LOW, "We're using direct I/O\n" );
} else {
DBG( DBG_LOW, "We're using libIEEE1284 I/O\n" );
}
_VAR_NOT_USED( port );
#endif
return _OK;
}
/** here we restore the port
/** Function to restore the port
*/
_LOC void MiscRestorePort( pScanData ps )
{
@ -548,7 +551,7 @@ _LOC void MiscRestorePort( pScanData ps )
/*Restore Port-Mode*/
#ifdef __KERNEL__
if (port_feature & PARPORT_MODE_PCECR ){
if( port_feature & PARPORT_MODE_PCECR ){
_OUTB_ECTL( ps, (Byte)ps->IO.lastPortMode );
_DO_UDELAY(1);
} else {
@ -556,13 +559,15 @@ _LOC void MiscRestorePort( pScanData ps )
_DO_UDELAY(1);
}
#else
if (port_feature & PPA_PROBE_ECR ){
if( port_feature & PPA_PROBE_ECR ){
_OUTB_ECTL(ps,ps->IO.lastPortMode);
}
#endif
}
/** starts a timer
/** Initializes a timer.
* @param timer - pointer to the timer to start
* @param us - timeout value in micro-seconds
*/
_LOC _INL void MiscStartTimer( pTimerDef timer , unsigned long us)
{
@ -574,10 +579,14 @@ _LOC _INL void MiscStartTimer( pTimerDef timer , unsigned long us)
gettimeofday(&start_time, NULL);
#endif
*timer = start_time.tv_sec * 1e6 + start_time.tv_usec + us;
*timer = start_time.tv_sec * 1e6 + start_time.tv_usec + us;
}
/** checks for timeout
/** Checks if a timer has been expired or not. In Kernel-mode, the scheduler
* will also be triggered, if the timer has not been expired.
* @param timer - pointer to the timer to check
* @return Function returns _E_TIMEOUT when the timer has been expired,
* otherwise _OK;
*/
_LOC _INL int MiscCheckTimer( pTimerDef timer )
{
@ -602,7 +611,10 @@ _LOC _INL int MiscCheckTimer( pTimerDef timer )
}
}
/** checks the function pointers
/** Checks the function pointers
* @param ps - pointer to the scanner data structure.
* @return Function returns _TRUE if everything is okay and _FALSE if a NULL
* ptr has been detected.
*/
#ifdef DEBUG
_LOC Bool MiscAllPointersSet( pScanData ps )
@ -624,6 +636,8 @@ _LOC Bool MiscAllPointersSet( pScanData ps )
#endif
/** registers this driver to use port "portAddr" (KERNEL-Mode only)
* @param ps - pointer to the scanner data structure.
* @param portAddr -
*/
_LOC int MiscRegisterPort( pScanData ps, int portAddr )
{
@ -642,8 +656,7 @@ _LOC int MiscRegisterPort( pScanData ps, int portAddr )
return _E_PORTSEARCH;
}
/*
* go through the list
/* go through the list
*/
for( ps->pp = NULL; NULL != pp; ) {
@ -679,7 +692,7 @@ _LOC int MiscRegisterPort( pScanData ps, int portAddr )
return _OK;
}
/** unregisters the port from driver (KERNEL-Mode only)
/** unregisters the port from driver
*/
_LOC void MiscUnregisterPort( pScanData ps )
{
@ -693,26 +706,29 @@ _LOC void MiscUnregisterPort( pScanData ps )
#endif
}
/** try to claim the port (KERNEL-Mode only)
/** Try to claim the port
* @param ps - pointer to the scanner data structure.
* @return Function returns _OK on success, otherwise _E_BUSY.
*/
_LOC int MiscClaimPort( pScanData ps )
{
#ifdef __KERNEL__
if( 0 == portIsClaimed[ps->devno] ) {
DBG( DBG_HIGH, "Try to claim the parport\n" );
if( 0 != parport_claim( ps->pardev ))
return _E_BUSY;
}
#ifdef __KERNEL__
if( 0 != parport_claim( ps->pardev )) {
#else
sanei_pp_claim( ps->pardev );
if( SANE_STATUS_GOOD != sanei_pp_claim( ps->pardev )) {
#endif
return _E_BUSY;
}
}
portIsClaimed[ps->devno]++;
return _OK;
}
/** release previously claimed port (KERNEL-Mode only)
/** Release previously claimed port
* @param ps - pointer to the scanner data structure
*/
_LOC void MiscReleasePort( pScanData ps )
{
@ -730,8 +746,8 @@ _LOC void MiscReleasePort( pScanData ps )
}
}
/*.............................................................................
* get random number
/** Get random number
* @return a random number.
*/
_LOC Long MiscLongRand( void )
{
@ -740,8 +756,9 @@ _LOC Long MiscLongRand( void )
return randomnum;
}
/*.............................................................................
* according to the id, the function returns a pointer to the model name
/** According to the id, the function returns a pointer to the model name
* @param id - internal id of the various scanner models.
* @return a pointer to the model-string.
*/
_LOC const char *MiscGetModelName( UShort id )
{

Wyświetl plik

@ -915,29 +915,28 @@ static int ptdrvShutdown( pScanData ps )
DBG( DBG_HIGH, "cleanup device %u\n", devno );
if( _NO_BASE != ps->sCaps.wIOBase ) {
if( _NO_BASE != ps->sCaps.wIOBase ) {
ptdrvStopLampTimer( ps );
ptdrvStopLampTimer( ps );
if( _OK == MiscClaimPort(ps)) {
if( _OK == MiscClaimPort(ps)) {
ps->PutToIdleMode( ps );
ps->PutToIdleMode( ps );
if( 0 != ps->lOffonEnd ) {
if( _IS_ASIC98(ps->sCaps.AsicID)) {
if( 0 != ps->lOffonEnd ) {
if( _IS_ASIC98(ps->sCaps.AsicID)) {
ps->AsicReg.RD_ScanControl &= ~_SCAN_LAMPS_ON;
} else {
ps->AsicReg.RD_ScanControl &= ~_SCAN_LAMP_ON;
} else {
ps->AsicReg.RD_ScanControl &= ~_SCAN_LAMP_ON;
}
IOCmdRegisterToScanner( ps, ps->RegScanControl,
IOCmdRegisterToScanner( ps, ps->RegScanControl,
ps->AsicReg.RD_ScanControl );
}
}
MiscReleasePort( ps );
}
}
}
MiscReleasePort( ps );
}
/*
* unregister the driver
/* unregister the driver
*/
MiscUnregisterPort( ps );

Wyświetl plik

@ -95,10 +95,10 @@
/*.............................................................................
* driver properties
*/
#define _DRV_NAME "pt_drv" /* driver's name */
#define _MAX_PTDEVS 4 /* support for 4 devices */
#define _MAX_BTNS 6 /* support for 6 buttons */
#define _PTDRV_MAJOR 40 /* our major number */
#define _DRV_NAME "pt_drv" /**< driver's name */
#define _MAX_PTDEVS 4 /**< support for 4 devices */
#define _MAX_BTNS 6 /**< support for 6 buttons */
#define _PTDRV_MAJOR 40 /**< our major number */
/*.............................................................................
* for port operations

Wyświetl plik

@ -87,7 +87,7 @@
#include "../include/sane/sanei.h"
#include "../include/sane/saneopts.h"
#define BACKEND_VERSION "0.01-4"
#define BACKEND_VERSION "0.01-5"
#define BACKEND_NAME plustek_pp
#include "../include/sane/sanei_backend.h"
#include "../include/sane/sanei_config.h"
@ -125,7 +125,7 @@ MODELSTR;
/* needed to statisfy the module code ... */
#define _PTDRV_V0 0
#define _PTDRV_V1 42
#define _PTDRV_V1 44
/* I know this is in general no good idea, but it works */
# include "plustek-pp_io.c"

Wyświetl plik

@ -5,8 +5,9 @@
#
# user either [direct] or [kernel] to access the scanner
# when using [kernel], device specifies the device-node, which is created
# by the kernel-modules loader
# by the kernel-module loader (applies only to Linux)
# when using [direct], device is used to set the parallel-port base address
# or a device-name suitable for libieee1284, i.e. parport0
#
[direct]
device 0x378
@ -22,6 +23,12 @@ option lampOff -1
# does not work or could not work correctly
#option mov 7
#
# example for accessing the scanner via libieee1284
#
[direct]
device parport0
#
# example for accessing the scanner via the kernel module
#