source: svn/trunk/newcon3bcm2_21bu/toolchain/mips-linux-uclibc/include/linux/parport_pc.h

Last change on this file was 2, checked in by jglee, 11 years ago

first commit

  • Property svn:executable set to *
File size: 6.5 KB
Line 
1#ifndef __LINUX_PARPORT_PC_H
2#define __LINUX_PARPORT_PC_H
3
4#include <asm/io.h>
5
6/* --- register definitions ------------------------------- */
7
8#define ECONTROL(p) ((p)->base_hi + 0x2)
9#define CONFIGB(p)  ((p)->base_hi + 0x1)
10#define CONFIGA(p)  ((p)->base_hi + 0x0)
11#define FIFO(p)     ((p)->base_hi + 0x0)
12#define EPPDATA(p)  ((p)->base    + 0x4)
13#define EPPADDR(p)  ((p)->base    + 0x3)
14#define CONTROL(p)  ((p)->base    + 0x2)
15#define STATUS(p)   ((p)->base    + 0x1)
16#define DATA(p)     ((p)->base    + 0x0)
17
18struct parport_pc_private {
19        /* Contents of CTR. */
20        unsigned char ctr;
21
22        /* Bitmask of writable CTR bits. */
23        unsigned char ctr_writable;
24
25        /* Whether or not there's an ECR. */
26        int ecr;
27
28        /* Number of PWords that FIFO will hold. */
29        int fifo_depth;
30
31        /* Number of bytes per portword. */
32        int pword;
33
34        /* Not used yet. */
35        int readIntrThreshold;
36        int writeIntrThreshold;
37
38        /* buffer suitable for DMA, if DMA enabled */
39        char *dma_buf;
40        dma_addr_t dma_handle;
41        struct pci_dev *dev;
42        struct list_head list;
43        struct parport *port;
44};
45
46struct parport_pc_via_data
47{
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 */
56        __u8 viacfg_function;
57        /* parallel port control register number */
58        __u8 viacfg_parport_control;
59        /* Parallel port base address register */
60        __u8 viacfg_parport_base;
61};
62
63static __inline__ void parport_pc_write_data(struct parport *p, unsigned char d)
64{
65#ifdef DEBUG_PARPORT
66        printk (KERN_DEBUG "parport_pc_write_data(%p,0x%02x)\n", p, d);
67#endif
68        outb(d, DATA(p));
69}
70
71static __inline__ unsigned char parport_pc_read_data(struct parport *p)
72{
73        unsigned char val = inb (DATA (p));
74#ifdef DEBUG_PARPORT
75        printk (KERN_DEBUG "parport_pc_read_data(%p) = 0x%02x\n",
76                p, val);
77#endif
78        return val;
79}
80
81#ifdef DEBUG_PARPORT
82extern __inline__ void dump_parport_state (char *str, struct parport *p)
83{
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 char *ecr_modes[] = {"SPP", "PS2", "PPFIFO", "ECP", "xXx", "yYy", "TST", "CFG"};
89        const struct parport_pc_private *priv = (parport_pc_private *)p->physport->private_data;
90        int i;
91
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");
98        for (i=0; i<2; i++) {
99                printk ("]  dcr(%s)=[", i ? "soft" : "hard");
100                dcr = i ? priv->ctr : inb (CONTROL (p));
101       
102                if (dcr & 0x20) {
103                        printk ("rev");
104                } else {
105                        printk ("fwd");
106                }
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");
112        }
113        printk ("]  dsr=[");
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");
119        printk ("]\n");
120        return;
121}
122#else   /* !DEBUG_PARPORT */
123#define dump_parport_state(args...)
124#endif  /* !DEBUG_PARPORT */
125
126/* __parport_pc_frob_control differs from parport_pc_frob_control in that
127 * it doesn't do any extra masking. */
128static __inline__ unsigned char __parport_pc_frob_control (struct parport *p,
129                                                           unsigned char mask,
130                                                           unsigned char val)
131{
132        struct parport_pc_private *priv = p->physport->private_data;
133        unsigned char ctr = priv->ctr;
134#ifdef DEBUG_PARPORT
135        printk (KERN_DEBUG
136                "__parport_pc_frob_control(%02x,%02x): %02x -> %02x\n",
137                mask, val, ctr, ((ctr & ~mask) ^ val) & priv->ctr_writable);
138#endif
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 */
143        return ctr;
144}
145
146static __inline__ void parport_pc_data_reverse (struct parport *p)
147{
148        __parport_pc_frob_control (p, 0x20, 0x20);
149}
150
151static __inline__ void parport_pc_data_forward (struct parport *p)
152{
153        __parport_pc_frob_control (p, 0x20, 0x00);
154}
155
156static __inline__ void parport_pc_write_control (struct parport *p,
157                                                 unsigned char d)
158{
159        const unsigned char wm = (PARPORT_CONTROL_STROBE |
160                                  PARPORT_CONTROL_AUTOFD |
161                                  PARPORT_CONTROL_INIT |
162                                  PARPORT_CONTROL_SELECT);
163
164        /* Take this out when drivers have adapted to newer interface. */
165        if (d & 0x20) {
166                printk (KERN_DEBUG "%s (%s): use data_reverse for this!\n",
167                        p->name, p->cad->name);
168                parport_pc_data_reverse (p);
169        }
170
171        __parport_pc_frob_control (p, wm, d & wm);
172}
173
174static __inline__ unsigned char parport_pc_read_control(struct parport *p)
175{
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 */
182}
183
184static __inline__ unsigned char parport_pc_frob_control (struct parport *p,
185                                                         unsigned char mask,
186                                                         unsigned char val)
187{
188        const unsigned char wm = (PARPORT_CONTROL_STROBE |
189                                  PARPORT_CONTROL_AUTOFD |
190                                  PARPORT_CONTROL_INIT |
191                                  PARPORT_CONTROL_SELECT);
192
193        /* Take this out when drivers have adapted to newer interface. */
194        if (mask & 0x20) {
195                printk (KERN_DEBUG "%s (%s): use data_%s for this!\n",
196                        p->name, p->cad->name,
197                        (val & 0x20) ? "reverse" : "forward");
198                if (val & 0x20)
199                        parport_pc_data_reverse (p);
200                else
201                        parport_pc_data_forward (p);
202        }
203
204        /* Restrict mask and val to control lines. */
205        mask &= wm;
206        val &= wm;
207
208        return __parport_pc_frob_control (p, mask, val);
209}
210
211static __inline__ unsigned char parport_pc_read_status(struct parport *p)
212{
213        return inb(STATUS(p));
214}
215
216
217static __inline__ void parport_pc_disable_irq(struct parport *p)
218{
219        __parport_pc_frob_control (p, 0x10, 0x00);
220}
221
222static __inline__ void parport_pc_enable_irq(struct parport *p)
223{
224        __parport_pc_frob_control (p, 0x10, 0x10);
225}
226
227extern void parport_pc_release_resources(struct parport *p);
228
229extern int parport_pc_claim_resources(struct parport *p);
230
231/* PCMCIA code will want to get us to look at a port.  Provide a mechanism. */
232extern struct parport *parport_pc_probe_port (unsigned long base,
233                                              unsigned long base_hi,
234                                              int irq, int dma,
235                                              struct pci_dev *dev);
236extern void parport_pc_unregister_port (struct parport *p);
237
238#endif
Note: See TracBrowser for help on using the repository browser.