Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
422 giacomo 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
 
18
struct 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
};
43
 
44
extern __inline__ void parport_pc_write_data(struct parport *p, unsigned char d)
45
{
46
#ifdef DEBUG_PARPORT
47
        printk (KERN_DEBUG "parport_pc_write_data(%p,0x%02x)\n", p, d);
48
#endif
49
        outb(d, DATA(p));
50
}
51
 
52
extern __inline__ unsigned char parport_pc_read_data(struct parport *p)
53
{
54
        unsigned char val = inb (DATA (p));
55
#ifdef DEBUG_PARPORT
56
        printk (KERN_DEBUG "parport_pc_read_data(%p) = 0x%02x\n",
57
                p, val);
58
#endif
59
        return val;
60
}
61
 
62
#ifdef DEBUG_PARPORT
63
extern __inline__ void dump_parport_state (char *str, struct parport *p)
64
{
65
        /* here's hoping that reading these ports won't side-effect anything underneath */
66
        unsigned char ecr = inb (ECONTROL (p));
67
        unsigned char dcr = inb (CONTROL (p));
68
        unsigned char dsr = inb (STATUS (p));
69
        static char *ecr_modes[] = {"SPP", "PS2", "PPFIFO", "ECP", "xXx", "yYy", "TST", "CFG"};
70
        const struct parport_pc_private *priv = (parport_pc_private *)p->physport->private_data;
71
        int i;
72
 
73
        printk (KERN_DEBUG "*** parport state (%s): ecr=[%s", str, ecr_modes[(ecr & 0xe0) >> 5]);
74
        if (ecr & 0x10) printk (",nErrIntrEn");
75
        if (ecr & 0x08) printk (",dmaEn");
76
        if (ecr & 0x04) printk (",serviceIntr");
77
        if (ecr & 0x02) printk (",f_full");
78
        if (ecr & 0x01) printk (",f_empty");
79
        for (i=0; i<2; i++) {
80
                printk ("]  dcr(%s)=[", i ? "soft" : "hard");
81
                dcr = i ? priv->ctr : inb (CONTROL (p));
82
 
83
                if (dcr & 0x20) {
84
                        printk ("rev");
85
                } else {
86
                        printk ("fwd");
87
                }
88
                if (dcr & 0x10) printk (",ackIntEn");
89
                if (!(dcr & 0x08)) printk (",N-SELECT-IN");
90
                if (dcr & 0x04) printk (",N-INIT");
91
                if (!(dcr & 0x02)) printk (",N-AUTOFD");
92
                if (!(dcr & 0x01)) printk (",N-STROBE");
93
        }
94
        printk ("]  dsr=[");
95
        if (!(dsr & 0x80)) printk ("BUSY");
96
        if (dsr & 0x40) printk (",N-ACK");
97
        if (dsr & 0x20) printk (",PERROR");
98
        if (dsr & 0x10) printk (",SELECT");
99
        if (dsr & 0x08) printk (",N-FAULT");
100
        printk ("]\n");
101
        return;
102
}
103
#else   /* !DEBUG_PARPORT */
104
#define dump_parport_state(args...)
105
#endif  /* !DEBUG_PARPORT */
106
 
107
/* __parport_pc_frob_control differs from parport_pc_frob_control in that
108
 * it doesn't do any extra masking. */
109
static __inline__ unsigned char __parport_pc_frob_control (struct parport *p,
110
                                                           unsigned char mask,
111
                                                           unsigned char val)
112
{
113
        struct parport_pc_private *priv = p->physport->private_data;
114
        unsigned char ctr = priv->ctr;
115
#ifdef DEBUG_PARPORT
116
        printk (KERN_DEBUG
117
                "__parport_pc_frob_control(%02x,%02x): %02x -> %02x\n",
118
                mask, val, ctr, ((ctr & ~mask) ^ val) & priv->ctr_writable);
119
#endif
120
        ctr = (ctr & ~mask) ^ val;
121
        ctr &= priv->ctr_writable; /* only write writable bits. */
122
        outb (ctr, CONTROL (p));
123
        priv->ctr = ctr;        /* Update soft copy */
124
        return ctr;
125
}
126
 
127
extern __inline__ void parport_pc_data_reverse (struct parport *p)
128
{
129
        __parport_pc_frob_control (p, 0x20, 0x20);
130
}
131
 
132
extern __inline__ void parport_pc_data_forward (struct parport *p)
133
{
134
        __parport_pc_frob_control (p, 0x20, 0x00);
135
}
136
 
137
extern __inline__ void parport_pc_write_control (struct parport *p,
138
                                                 unsigned char d)
139
{
140
        const unsigned char wm = (PARPORT_CONTROL_STROBE |
141
                                  PARPORT_CONTROL_AUTOFD |
142
                                  PARPORT_CONTROL_INIT |
143
                                  PARPORT_CONTROL_SELECT);
144
 
145
        /* Take this out when drivers have adapted to newer interface. */
146
        if (d & 0x20) {
147
                printk (KERN_DEBUG "%s (%s): use data_reverse for this!\n",
148
                        p->name, p->cad->name);
149
                parport_pc_data_reverse (p);
150
        }
151
 
152
        __parport_pc_frob_control (p, wm, d & wm);
153
}
154
 
155
extern __inline__ unsigned char parport_pc_read_control(struct parport *p)
156
{
157
        const unsigned char rm = (PARPORT_CONTROL_STROBE |
158
                                  PARPORT_CONTROL_AUTOFD |
159
                                  PARPORT_CONTROL_INIT |
160
                                  PARPORT_CONTROL_SELECT);
161
        const struct parport_pc_private *priv = p->physport->private_data;
162
        return priv->ctr & rm; /* Use soft copy */
163
}
164
 
165
extern __inline__ unsigned char parport_pc_frob_control (struct parport *p,
166
                                                         unsigned char mask,
167
                                                         unsigned char val)
168
{
169
        const unsigned char wm = (PARPORT_CONTROL_STROBE |
170
                                  PARPORT_CONTROL_AUTOFD |
171
                                  PARPORT_CONTROL_INIT |
172
                                  PARPORT_CONTROL_SELECT);
173
 
174
        /* Take this out when drivers have adapted to newer interface. */
175
        if (mask & 0x20) {
176
                printk (KERN_DEBUG "%s (%s): use data_%s for this!\n",
177
                        p->name, p->cad->name,
178
                        (val & 0x20) ? "reverse" : "forward");
179
                if (val & 0x20)
180
                        parport_pc_data_reverse (p);
181
                else
182
                        parport_pc_data_forward (p);
183
        }
184
 
185
        /* Restrict mask and val to control lines. */
186
        mask &= wm;
187
        val &= wm;
188
 
189
        return __parport_pc_frob_control (p, mask, val);
190
}
191
 
192
extern __inline__ unsigned char parport_pc_read_status(struct parport *p)
193
{
194
        return inb(STATUS(p));
195
}
196
 
197
 
198
extern __inline__ void parport_pc_disable_irq(struct parport *p)
199
{
200
        __parport_pc_frob_control (p, 0x10, 0x00);
201
}
202
 
203
extern __inline__ void parport_pc_enable_irq(struct parport *p)
204
{
205
        __parport_pc_frob_control (p, 0x10, 0x10);
206
}
207
 
208
extern void parport_pc_release_resources(struct parport *p);
209
 
210
extern int parport_pc_claim_resources(struct parport *p);
211
 
212
extern void parport_pc_init_state(struct pardevice *, struct parport_state *s);
213
 
214
extern void parport_pc_save_state(struct parport *p, struct parport_state *s);
215
 
216
extern void parport_pc_restore_state(struct parport *p, struct parport_state *s);
217
 
218
/* PCMCIA code will want to get us to look at a port.  Provide a mechanism. */
219
extern struct parport *parport_pc_probe_port (unsigned long base,
220
                                              unsigned long base_hi,
221
                                              int irq, int dma,
222
                                              struct pci_dev *dev);
223
extern void parport_pc_unregister_port (struct parport *p);
224
 
225
#endif