1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __LINUX_PARPORT_PC_H
3 #define __LINUX_PARPORT_PC_H
7 /* --- register definitions ------------------------------- */
9 #define ECONTROL(p) ((p)->base_hi + 0x2)
10 #define CONFIGB(p) ((p)->base_hi + 0x1)
11 #define CONFIGA(p) ((p)->base_hi + 0x0)
12 #define FIFO(p) ((p)->base_hi + 0x0)
13 #define EPPDATA(p) ((p)->base + 0x4)
14 #define EPPADDR(p) ((p)->base + 0x3)
15 #define CONTROL(p) ((p)->base + 0x2)
16 #define STATUS(p) ((p)->base + 0x1)
17 #define DATA(p) ((p)->base + 0x0)
19 struct parport_pc_private
{
20 /* Contents of CTR. */
23 /* Bitmask of writable CTR bits. */
24 unsigned char ctr_writable
;
26 /* Whether or not there's an ECR. */
29 /* Number of PWords that FIFO will hold. */
32 /* Number of bytes per portword. */
36 int readIntrThreshold
;
37 int writeIntrThreshold
;
39 /* buffer suitable for DMA, if DMA enabled */
41 dma_addr_t dma_handle
;
42 struct list_head list
;
46 struct parport_pc_via_data
48 /* ISA PnP IRQ routing register 1 */
49 u8 via_pci_parport_irq_reg
;
50 /* ISA PnP DMA request routing register */
51 u8 via_pci_parport_dma_reg
;
52 /* Register and value to enable SuperIO configuration access */
53 u8 via_pci_superio_config_reg
;
54 u8 via_pci_superio_config_data
;
55 /* SuperIO function register number */
57 /* parallel port control register number */
58 u8 viacfg_parport_control
;
59 /* Parallel port base address register */
60 u8 viacfg_parport_base
;
63 static __inline__
void parport_pc_write_data(struct parport
*p
, unsigned char d
)
66 printk (KERN_DEBUG
"parport_pc_write_data(%p,0x%02x)\n", p
, d
);
71 static __inline__
unsigned char parport_pc_read_data(struct parport
*p
)
73 unsigned char val
= inb (DATA (p
));
75 printk (KERN_DEBUG
"parport_pc_read_data(%p) = 0x%02x\n",
82 static inline void dump_parport_state (char *str
, struct parport
*p
)
84 /* here's hoping that reading these ports won't side-effect anything underneath */
85 unsigned char ecr
= inb (ECONTROL (p
));
86 unsigned char dcr
= inb (CONTROL (p
));
87 unsigned char dsr
= inb (STATUS (p
));
88 static const char *const ecr_modes
[] = {"SPP", "PS2", "PPFIFO", "ECP", "xXx", "yYy", "TST", "CFG"};
89 const struct parport_pc_private
*priv
= p
->physport
->private_data
;
92 printk (KERN_DEBUG
"*** parport state (%s): ecr=[%s", str
, ecr_modes
[(ecr
& 0xe0) >> 5]);
93 if (ecr
& 0x10) printk (",nErrIntrEn");
94 if (ecr
& 0x08) printk (",dmaEn");
95 if (ecr
& 0x04) printk (",serviceIntr");
96 if (ecr
& 0x02) printk (",f_full");
97 if (ecr
& 0x01) printk (",f_empty");
99 printk ("] dcr(%s)=[", i
? "soft" : "hard");
100 dcr
= i
? priv
->ctr
: inb (CONTROL (p
));
107 if (dcr
& 0x10) printk (",ackIntEn");
108 if (!(dcr
& 0x08)) printk (",N-SELECT-IN");
109 if (dcr
& 0x04) printk (",N-INIT");
110 if (!(dcr
& 0x02)) printk (",N-AUTOFD");
111 if (!(dcr
& 0x01)) printk (",N-STROBE");
114 if (!(dsr
& 0x80)) printk ("BUSY");
115 if (dsr
& 0x40) printk (",N-ACK");
116 if (dsr
& 0x20) printk (",PERROR");
117 if (dsr
& 0x10) printk (",SELECT");
118 if (dsr
& 0x08) printk (",N-FAULT");
122 #else /* !DEBUG_PARPORT */
123 #define dump_parport_state(args...)
124 #endif /* !DEBUG_PARPORT */
126 /* __parport_pc_frob_control differs from parport_pc_frob_control in that
127 * it doesn't do any extra masking. */
128 static __inline__
unsigned char __parport_pc_frob_control (struct parport
*p
,
132 struct parport_pc_private
*priv
= p
->physport
->private_data
;
133 unsigned char ctr
= priv
->ctr
;
136 "__parport_pc_frob_control(%02x,%02x): %02x -> %02x\n",
137 mask
, val
, ctr
, ((ctr
& ~mask
) ^ val
) & priv
->ctr_writable
);
139 ctr
= (ctr
& ~mask
) ^ val
;
140 ctr
&= priv
->ctr_writable
; /* only write writable bits. */
141 outb (ctr
, CONTROL (p
));
142 priv
->ctr
= ctr
; /* Update soft copy */
146 static __inline__
void parport_pc_data_reverse (struct parport
*p
)
148 __parport_pc_frob_control (p
, 0x20, 0x20);
151 static __inline__
void parport_pc_data_forward (struct parport
*p
)
153 __parport_pc_frob_control (p
, 0x20, 0x00);
156 static __inline__
void parport_pc_write_control (struct parport
*p
,
159 const unsigned char wm
= (PARPORT_CONTROL_STROBE
|
160 PARPORT_CONTROL_AUTOFD
|
161 PARPORT_CONTROL_INIT
|
162 PARPORT_CONTROL_SELECT
);
164 /* Take this out when drivers have adapted to newer interface. */
166 printk (KERN_DEBUG
"%s (%s): use data_reverse for this!\n",
167 p
->name
, p
->cad
->name
);
168 parport_pc_data_reverse (p
);
171 __parport_pc_frob_control (p
, wm
, d
& wm
);
174 static __inline__
unsigned char parport_pc_read_control(struct parport
*p
)
176 const unsigned char rm
= (PARPORT_CONTROL_STROBE
|
177 PARPORT_CONTROL_AUTOFD
|
178 PARPORT_CONTROL_INIT
|
179 PARPORT_CONTROL_SELECT
);
180 const struct parport_pc_private
*priv
= p
->physport
->private_data
;
181 return priv
->ctr
& rm
; /* Use soft copy */
184 static __inline__
unsigned char parport_pc_frob_control (struct parport
*p
,
188 const unsigned char wm
= (PARPORT_CONTROL_STROBE
|
189 PARPORT_CONTROL_AUTOFD
|
190 PARPORT_CONTROL_INIT
|
191 PARPORT_CONTROL_SELECT
);
193 /* Take this out when drivers have adapted to newer interface. */
195 printk (KERN_DEBUG
"%s (%s): use data_%s for this!\n",
196 p
->name
, p
->cad
->name
,
197 (val
& 0x20) ? "reverse" : "forward");
199 parport_pc_data_reverse (p
);
201 parport_pc_data_forward (p
);
204 /* Restrict mask and val to control lines. */
208 return __parport_pc_frob_control (p
, mask
, val
);
211 static __inline__
unsigned char parport_pc_read_status(struct parport
*p
)
213 return inb(STATUS(p
));
217 static __inline__
void parport_pc_disable_irq(struct parport
*p
)
219 __parport_pc_frob_control (p
, 0x10, 0x00);
222 static __inline__
void parport_pc_enable_irq(struct parport
*p
)
224 __parport_pc_frob_control (p
, 0x10, 0x10);
227 extern void parport_pc_release_resources(struct parport
*p
);
229 extern int parport_pc_claim_resources(struct parport
*p
);
231 /* PCMCIA code will want to get us to look at a port. Provide a mechanism. */
232 extern struct parport
*parport_pc_probe_port(unsigned long base
,
233 unsigned long base_hi
,
237 extern void parport_pc_unregister_port(struct parport
*p
);