]>
git.zerfleddert.de Git - usb-driver/blob - parport.c
57ab08355593964f4b15ed5f869dd1a9ec9f8cc5
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;
23 for (i
= 0; i
< num
; i
++) {
24 DPRINTF("dwPort: 0x%lx, cmdTrans: %lu, dwbytes: %ld, fautoinc: %ld, dwoptions: %ld\n",
25 (unsigned long)tr
[i
].dwPort
, tr
[i
].cmdTrans
, tr
[i
].dwBytes
,
26 tr
[i
].fAutoinc
, tr
[i
].dwOptions
);
28 port
= (unsigned long)tr
[i
].dwPort
;
29 val
= tr
[i
].Data
.Byte
;
32 if (tr
[i
].cmdTrans
== 13)
33 DPRINTF("write byte: %d\n", val
);
39 if (port
== ppbase
+ PP_DATA
) {
40 DPRINTF("data port\n");
41 switch(tr
[i
].cmdTrans
) {
43 ret
= 0; /* We don't support reading of the data port */
47 ret
= ioctl(parportfd
, PPWDATA
, &val
);
52 fprintf(stderr
,"!!!Unsupported TRANSFER command: %lu!!!\n", tr
[i
].cmdTrans
);
56 } else if (port
== ppbase
+ PP_STATUS
) {
57 DPRINTF("status port (last write: %d)\n", last_pp_write
);
58 switch(tr
[i
].cmdTrans
) {
60 ret
= ioctl(parportfd
, PPRSTATUS
, &val
);
61 #ifdef FORCE_PC3_IDENT
63 if (last_pp_write
& 0x40)
71 ret
= 0; /* Status Port is readonly */
75 fprintf(stderr
,"!!!Unsupported TRANSFER command: %lu!!!\n", tr
[i
].cmdTrans
);
79 } else if (port
== ppbase
+ PP_CONTROL
) {
80 DPRINTF("control port\n");
81 switch(tr
[i
].cmdTrans
) {
83 ret
= ioctl(parportfd
, PPRCONTROL
, &val
);
87 ret
= ioctl(parportfd
, PPWCONTROL
, &val
);
91 fprintf(stderr
,"!!!Unsupported TRANSFER command: %lu!!!\n", tr
[i
].cmdTrans
);
95 } else if ((port
== ecpbase
+ PP_ECP_CFGA
) && ecpbase
) {
96 DPRINTF("ECP_CFGA port\n");
97 } else if ((port
== ecpbase
+ PP_ECP_CFGB
) && ecpbase
) {
98 DPRINTF("ECP_CFGB port\n");
99 } else if ((port
== ecpbase
+ PP_ECP_ECR
) && ecpbase
) {
100 DPRINTF("ECP_ECR port\n");
102 DPRINTF("access to unsupported address range!\n");
106 tr
[i
].Data
.Byte
= val
;
108 DPRINTF("dwPortReturn: 0x%lx, cmdTrans: %lu, dwbytes: %ld, fautoinc: %ld, dwoptions: %ld\n",
109 (unsigned long)tr
[i
].dwPort
, tr
[i
].cmdTrans
, tr
[i
].dwBytes
,
110 tr
[i
].fAutoinc
, tr
[i
].dwOptions
);
112 if (tr
[i
].cmdTrans
== 10)
113 DPRINTF("read byte: %d\n", tr
[i
].Data
.Byte
);
120 int parport_open(int num
) {
124 snprintf(ppdev
, sizeof(ppdev
), "/dev/parport%u", num
);
125 DPRINTF("opening %s\n", ppdev
);
126 parportfd
= open(ppdev
, O_RDWR
|O_EXCL
);
129 fprintf(stderr
,"Can't open %s: %s\n", ppdev
, strerror(errno
));
132 if (parportfd
>= 0) {
135 if (ioctl(parportfd
, PPCLAIM
) == -1)
138 pmode
= IEEE1284_MODE_COMPAT
;
139 if (ioctl(parportfd
, PPNEGOT
, &pmode
) == -1)
143 if (cr
->Card
.dwItems
> 1 && cr
->Card
.Item
[1].I
.IO
.dwAddr
) {
144 DPRINTF("ECP mode requested\n");
145 ecpbase
= (unsigned long)cr
->Card
.Item
[1].I
.IO
.dwAddr
;
146 /* TODO: Implement ECP mode */
147 pmode
= IEEE1284_MODE_ECP
;
149 if (ioctl(parportfd
, PPNEGOT
, &pmode
) == -1) {
151 pmode
= IEEE1284_MODE_COMPAT
;
152 if (ioctl(parportfd
, PPNEGOT
, &pmode
) == -1)
162 void parport_close(int handle
) {
163 if (parportfd
== handle
&& parportfd
>= 0) {
164 ioctl(parportfd
, PPRELEASE
);