Merge tag 'trace-v5.15-3' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt...
[linux-2.6-microblaze.git] / include / linux / parport_pc.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __LINUX_PARPORT_PC_H
3 #define __LINUX_PARPORT_PC_H
4
5 #include <asm/io.h>
6
7 /* --- register definitions ------------------------------- */
8
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)
18
19 struct parport_pc_private {
20         /* Contents of CTR. */
21         unsigned char ctr;
22
23         /* Bitmask of writable CTR bits. */
24         unsigned char ctr_writable;
25
26         /* Whether or not there's an ECR. */
27         int ecr;
28
29         /* Number of PWords that FIFO will hold. */
30         int fifo_depth;
31
32         /* Number of bytes per portword. */
33         int pword;
34
35         /* Not used yet. */
36         int readIntrThreshold;
37         int writeIntrThreshold;
38
39         /* buffer suitable for DMA, if DMA enabled */
40         char *dma_buf;
41         dma_addr_t dma_handle;
42         struct list_head list;
43         struct parport *port;
44 };
45
46 struct 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
63 static __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
71 static __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
82 static 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 const char *const ecr_modes[] = {"SPP", "PS2", "PPFIFO", "ECP", "xXx", "yYy", "TST", "CFG"};
89         const struct parport_pc_private *priv = 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. */
128 static __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
146 static __inline__ void parport_pc_data_reverse (struct parport *p)
147 {
148         __parport_pc_frob_control (p, 0x20, 0x20);
149 }
150
151 static __inline__ void parport_pc_data_forward (struct parport *p)
152 {
153         __parport_pc_frob_control (p, 0x20, 0x00);
154 }
155
156 static __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
174 static __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
184 static __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
211 static __inline__ unsigned char parport_pc_read_status(struct parport *p)
212 {
213         return inb(STATUS(p));
214 }
215
216
217 static __inline__ void parport_pc_disable_irq(struct parport *p)
218 {
219         __parport_pc_frob_control (p, 0x10, 0x00);
220 }
221
222 static __inline__ void parport_pc_enable_irq(struct parport *p)
223 {
224         __parport_pc_frob_control (p, 0x10, 0x10);
225 }
226
227 extern void parport_pc_release_resources(struct parport *p);
228
229 extern 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. */
232 extern struct parport *parport_pc_probe_port(unsigned long base,
233                                              unsigned long base_hi,
234                                              int irq, int dma,
235                                              struct device *dev,
236                                              int irqflags);
237 extern void parport_pc_unregister_port(struct parport *p);
238
239 #endif