]>
cvs.zerfleddert.de Git - usb-driver/blob - parport.c
9 #include <linux/parport.h>
10 #include <linux/ppdev.h>
11 #include "usb-driver.h"
14 static int parportfd
= -1;
16 int parport_transfer(WD_TRANSFER
*tr
, int fd
, unsigned int request
, int ppbase
, int ecpbase
, int num
) {
21 static unsigned char last_pp_write
= 0;
26 if (ioctl(parportfd
, PPCLAIM
) == -1)
29 for (i
= 0; i
< num
; i
++) {
30 DPRINTF("dwPort: 0x%lx, cmdTrans: %lu, dwbytes: %ld, fautoinc: %ld, dwoptions: %ld\n",
31 (unsigned long)tr
[i
].dwPort
, tr
[i
].cmdTrans
, tr
[i
].dwBytes
,
32 tr
[i
].fAutoinc
, tr
[i
].dwOptions
);
34 port
= (unsigned long)tr
[i
].dwPort
;
35 val
= tr
[i
].Data
.Byte
;
38 if (tr
[i
].cmdTrans
== 13)
39 DPRINTF("write byte: %d\n", val
);
42 if (port
== ppbase
+ PP_DATA
) {
43 DPRINTF("data port\n");
44 switch(tr
[i
].cmdTrans
) {
46 ret
= 0; /* We don't support reading of the data port */
50 ret
= ioctl(parportfd
, PPWDATA
, &val
);
55 fprintf(stderr
,"!!!Unsupported TRANSFER command: %lu!!!\n", tr
[i
].cmdTrans
);
59 } else if (port
== ppbase
+ PP_STATUS
) {
60 DPRINTF("status port (last write: %d)\n", last_pp_write
);
61 switch(tr
[i
].cmdTrans
) {
63 ret
= ioctl(parportfd
, PPRSTATUS
, &val
);
64 #ifdef FORCE_PC3_IDENT
66 if (last_pp_write
& 0x40)
74 ret
= 0; /* Status Port is readonly */
78 fprintf(stderr
,"!!!Unsupported TRANSFER command: %lu!!!\n", tr
[i
].cmdTrans
);
82 } else if (port
== ppbase
+ PP_CONTROL
) {
83 DPRINTF("control port\n");
84 switch(tr
[i
].cmdTrans
) {
86 ret
= ioctl(parportfd
, PPRCONTROL
, &val
);
90 ret
= ioctl(parportfd
, PPWCONTROL
, &val
);
94 fprintf(stderr
,"!!!Unsupported TRANSFER command: %lu!!!\n", tr
[i
].cmdTrans
);
98 } else if ((port
== ecpbase
+ PP_ECP_CFGA
) && ecpbase
) {
99 DPRINTF("ECP_CFGA port\n");
100 } else if ((port
== ecpbase
+ PP_ECP_CFGB
) && ecpbase
) {
101 DPRINTF("ECP_CFGB port\n");
102 } else if ((port
== ecpbase
+ PP_ECP_ECR
) && ecpbase
) {
103 DPRINTF("ECP_ECR port\n");
105 DPRINTF("access to unsupported address range!\n");
109 tr
[i
].Data
.Byte
= val
;
111 DPRINTF("dwPortReturn: 0x%lx, cmdTrans: %lu, dwbytes: %ld, fautoinc: %ld, dwoptions: %ld\n",
112 (unsigned long)tr
[i
].dwPort
, tr
[i
].cmdTrans
, tr
[i
].dwBytes
,
113 tr
[i
].fAutoinc
, tr
[i
].dwOptions
);
115 if (tr
[i
].cmdTrans
== 10)
116 DPRINTF("read byte: %d\n", tr
[i
].Data
.Byte
);
120 ioctl(parportfd
, PPRELEASE
);
125 int parport_open(int num
) {
129 snprintf(ppdev
, sizeof(ppdev
), "/dev/parport%u", num
);
130 DPRINTF("opening %s\n", ppdev
);
131 parportfd
= open(ppdev
, O_RDWR
|O_EXCL
);
134 fprintf(stderr
,"Can't open %s: %s\n", ppdev
, strerror(errno
));
137 if (parportfd
>= 0) {
140 if (ioctl(parportfd
, PPCLAIM
) == -1)
143 pmode
= IEEE1284_MODE_COMPAT
;
144 if (ioctl(parportfd
, PPNEGOT
, &pmode
) == -1)
147 ioctl(parportfd
, PPRELEASE
);
149 if (cr
->Card
.dwItems
> 1 && cr
->Card
.Item
[1].I
.IO
.dwAddr
) {
150 DPRINTF("ECP mode requested\n");
151 ecpbase
= (unsigned long)cr
->Card
.Item
[1].I
.IO
.dwAddr
;
152 /* TODO: Implement ECP mode */
153 pmode
= IEEE1284_MODE_ECP
;
155 if (ioctl(parportfd
, PPNEGOT
, &pmode
) == -1) {
157 pmode
= IEEE1284_MODE_COMPAT
;
158 if (ioctl(parportfd
, PPNEGOT
, &pmode
) == -1)
168 void parport_close(int handle
) {
169 if (parportfd
== handle
&& parportfd
>= 0) {
170 ioctl(parportfd
, PPRELEASE
);