0001
0002 #ifndef __LINUX_PARPORT_PC_H
0003 #define __LINUX_PARPORT_PC_H
0004
0005 #include <asm/io.h>
0006
0007
0008
0009 #define ECONTROL(p) ((p)->base_hi + 0x2)
0010 #define CONFIGB(p) ((p)->base_hi + 0x1)
0011 #define CONFIGA(p) ((p)->base_hi + 0x0)
0012 #define FIFO(p) ((p)->base_hi + 0x0)
0013 #define EPPDATA(p) ((p)->base + 0x4)
0014 #define EPPADDR(p) ((p)->base + 0x3)
0015 #define CONTROL(p) ((p)->base + 0x2)
0016 #define STATUS(p) ((p)->base + 0x1)
0017 #define DATA(p) ((p)->base + 0x0)
0018
0019 struct parport_pc_private {
0020
0021 unsigned char ctr;
0022
0023
0024 unsigned char ctr_writable;
0025
0026
0027 int ecr;
0028
0029
0030 int fifo_depth;
0031
0032
0033 int pword;
0034
0035
0036 int readIntrThreshold;
0037 int writeIntrThreshold;
0038
0039
0040 char *dma_buf;
0041 dma_addr_t dma_handle;
0042 struct list_head list;
0043 struct parport *port;
0044 };
0045
0046 struct parport_pc_via_data
0047 {
0048
0049 u8 via_pci_parport_irq_reg;
0050
0051 u8 via_pci_parport_dma_reg;
0052
0053 u8 via_pci_superio_config_reg;
0054 u8 via_pci_superio_config_data;
0055
0056 u8 viacfg_function;
0057
0058 u8 viacfg_parport_control;
0059
0060 u8 viacfg_parport_base;
0061 };
0062
0063 static __inline__ void parport_pc_write_data(struct parport *p, unsigned char d)
0064 {
0065 #ifdef DEBUG_PARPORT
0066 printk (KERN_DEBUG "parport_pc_write_data(%p,0x%02x)\n", p, d);
0067 #endif
0068 outb(d, DATA(p));
0069 }
0070
0071 static __inline__ unsigned char parport_pc_read_data(struct parport *p)
0072 {
0073 unsigned char val = inb (DATA (p));
0074 #ifdef DEBUG_PARPORT
0075 printk (KERN_DEBUG "parport_pc_read_data(%p) = 0x%02x\n",
0076 p, val);
0077 #endif
0078 return val;
0079 }
0080
0081 #ifdef DEBUG_PARPORT
0082 static inline void dump_parport_state (char *str, struct parport *p)
0083 {
0084
0085 unsigned char ecr = inb (ECONTROL (p));
0086 unsigned char dcr = inb (CONTROL (p));
0087 unsigned char dsr = inb (STATUS (p));
0088 static const char *const ecr_modes[] = {"SPP", "PS2", "PPFIFO", "ECP", "xXx", "yYy", "TST", "CFG"};
0089 const struct parport_pc_private *priv = p->physport->private_data;
0090 int i;
0091
0092 printk (KERN_DEBUG "*** parport state (%s): ecr=[%s", str, ecr_modes[(ecr & 0xe0) >> 5]);
0093 if (ecr & 0x10) printk (",nErrIntrEn");
0094 if (ecr & 0x08) printk (",dmaEn");
0095 if (ecr & 0x04) printk (",serviceIntr");
0096 if (ecr & 0x02) printk (",f_full");
0097 if (ecr & 0x01) printk (",f_empty");
0098 for (i=0; i<2; i++) {
0099 printk ("] dcr(%s)=[", i ? "soft" : "hard");
0100 dcr = i ? priv->ctr : inb (CONTROL (p));
0101
0102 if (dcr & 0x20) {
0103 printk ("rev");
0104 } else {
0105 printk ("fwd");
0106 }
0107 if (dcr & 0x10) printk (",ackIntEn");
0108 if (!(dcr & 0x08)) printk (",N-SELECT-IN");
0109 if (dcr & 0x04) printk (",N-INIT");
0110 if (!(dcr & 0x02)) printk (",N-AUTOFD");
0111 if (!(dcr & 0x01)) printk (",N-STROBE");
0112 }
0113 printk ("] dsr=[");
0114 if (!(dsr & 0x80)) printk ("BUSY");
0115 if (dsr & 0x40) printk (",N-ACK");
0116 if (dsr & 0x20) printk (",PERROR");
0117 if (dsr & 0x10) printk (",SELECT");
0118 if (dsr & 0x08) printk (",N-FAULT");
0119 printk ("]\n");
0120 return;
0121 }
0122 #else
0123 #define dump_parport_state(args...)
0124 #endif
0125
0126
0127
0128 static __inline__ unsigned char __parport_pc_frob_control (struct parport *p,
0129 unsigned char mask,
0130 unsigned char val)
0131 {
0132 struct parport_pc_private *priv = p->physport->private_data;
0133 unsigned char ctr = priv->ctr;
0134 #ifdef DEBUG_PARPORT
0135 printk (KERN_DEBUG
0136 "__parport_pc_frob_control(%02x,%02x): %02x -> %02x\n",
0137 mask, val, ctr, ((ctr & ~mask) ^ val) & priv->ctr_writable);
0138 #endif
0139 ctr = (ctr & ~mask) ^ val;
0140 ctr &= priv->ctr_writable;
0141 outb (ctr, CONTROL (p));
0142 priv->ctr = ctr;
0143 return ctr;
0144 }
0145
0146 static __inline__ void parport_pc_data_reverse (struct parport *p)
0147 {
0148 __parport_pc_frob_control (p, 0x20, 0x20);
0149 }
0150
0151 static __inline__ void parport_pc_data_forward (struct parport *p)
0152 {
0153 __parport_pc_frob_control (p, 0x20, 0x00);
0154 }
0155
0156 static __inline__ void parport_pc_write_control (struct parport *p,
0157 unsigned char d)
0158 {
0159 const unsigned char wm = (PARPORT_CONTROL_STROBE |
0160 PARPORT_CONTROL_AUTOFD |
0161 PARPORT_CONTROL_INIT |
0162 PARPORT_CONTROL_SELECT);
0163
0164
0165 if (d & 0x20) {
0166 printk (KERN_DEBUG "%s (%s): use data_reverse for this!\n",
0167 p->name, p->cad->name);
0168 parport_pc_data_reverse (p);
0169 }
0170
0171 __parport_pc_frob_control (p, wm, d & wm);
0172 }
0173
0174 static __inline__ unsigned char parport_pc_read_control(struct parport *p)
0175 {
0176 const unsigned char rm = (PARPORT_CONTROL_STROBE |
0177 PARPORT_CONTROL_AUTOFD |
0178 PARPORT_CONTROL_INIT |
0179 PARPORT_CONTROL_SELECT);
0180 const struct parport_pc_private *priv = p->physport->private_data;
0181 return priv->ctr & rm;
0182 }
0183
0184 static __inline__ unsigned char parport_pc_frob_control (struct parport *p,
0185 unsigned char mask,
0186 unsigned char val)
0187 {
0188 const unsigned char wm = (PARPORT_CONTROL_STROBE |
0189 PARPORT_CONTROL_AUTOFD |
0190 PARPORT_CONTROL_INIT |
0191 PARPORT_CONTROL_SELECT);
0192
0193
0194 if (mask & 0x20) {
0195 printk (KERN_DEBUG "%s (%s): use data_%s for this!\n",
0196 p->name, p->cad->name,
0197 (val & 0x20) ? "reverse" : "forward");
0198 if (val & 0x20)
0199 parport_pc_data_reverse (p);
0200 else
0201 parport_pc_data_forward (p);
0202 }
0203
0204
0205 mask &= wm;
0206 val &= wm;
0207
0208 return __parport_pc_frob_control (p, mask, val);
0209 }
0210
0211 static __inline__ unsigned char parport_pc_read_status(struct parport *p)
0212 {
0213 return inb(STATUS(p));
0214 }
0215
0216
0217 static __inline__ void parport_pc_disable_irq(struct parport *p)
0218 {
0219 __parport_pc_frob_control (p, 0x10, 0x00);
0220 }
0221
0222 static __inline__ void parport_pc_enable_irq(struct parport *p)
0223 {
0224 __parport_pc_frob_control (p, 0x10, 0x10);
0225 }
0226
0227 extern void parport_pc_release_resources(struct parport *p);
0228
0229 extern int parport_pc_claim_resources(struct parport *p);
0230
0231
0232 extern struct parport *parport_pc_probe_port(unsigned long base,
0233 unsigned long base_hi,
0234 int irq, int dma,
0235 struct device *dev,
0236 int irqflags);
0237 extern void parport_pc_unregister_port(struct parport *p);
0238
0239 #endif