Add rscript invocation variables
[openwrt.git] / openwrt / package / linux / kernel-source / drivers / parport / parport_splink.c
1 /* Low-level parallel port routines for the ASUS WL-500g built-in port
2 *
3 * Author: Nuno Grilo <nuno.grilo@netcabo.pt>
4 * Based on parport_pc source
5 */
6
7 #include <linux/config.h>
8 #include <linux/module.h>
9 #include <linux/init.h>
10 #include <linux/ioport.h>
11 #include <linux/kernel.h>
12 #include <linux/slab.h>
13 #include <linux/parport.h>
14 #include <linux/parport_pc.h>
15
16 #define SPLINK_ADDRESS 0xBF800010
17
18 #undef DEBUG
19
20 #ifdef DEBUG
21 #define DPRINTK printk
22 #else
23 #define DPRINTK(stuff...)
24 #endif
25
26
27 /* __parport_splink_frob_control differs from parport_splink_frob_control in that
28 * it doesn't do any extra masking. */
29 static __inline__ unsigned char __parport_splink_frob_control (struct parport *p,
30 unsigned char mask,
31 unsigned char val)
32 {
33 struct parport_pc_private *priv = p->physport->private_data;
34 unsigned char *io = (unsigned char *) p->base;
35 unsigned char ctr = priv->ctr;
36 #ifdef DEBUG_PARPORT
37 printk (KERN_DEBUG
38 "__parport_splink_frob_control(%02x,%02x): %02x -> %02x\n",
39 mask, val, ctr, ((ctr & ~mask) ^ val) & priv->ctr_writable);
40 #endif
41 ctr = (ctr & ~mask) ^ val;
42 ctr &= priv->ctr_writable; /* only write writable bits. */
43 *(io+2) = ctr;
44 priv->ctr = ctr; /* Update soft copy */
45 return ctr;
46 }
47
48
49
50 static void parport_splink_data_forward (struct parport *p)
51 {
52 DPRINTK(KERN_DEBUG "parport_splink: parport_data_forward called\n");
53 __parport_splink_frob_control (p, 0x20, 0);
54 }
55
56 static void parport_splink_data_reverse (struct parport *p)
57 {
58 DPRINTK(KERN_DEBUG "parport_splink: parport_data_forward called\n");
59 __parport_splink_frob_control (p, 0x20, 0x20);
60 }
61
62 /*
63 static void parport_splink_interrupt(int irq, void *dev_id, struct pt_regs *regs)
64 {
65 DPRINTK(KERN_DEBUG "parport_splink: IRQ handler called\n");
66 parport_generic_irq(irq, (struct parport *) dev_id, regs);
67 }
68 */
69
70 static void parport_splink_enable_irq(struct parport *p)
71 {
72 DPRINTK(KERN_DEBUG "parport_splink: parport_splink_enable_irq called\n");
73 __parport_splink_frob_control (p, 0x10, 0x10);
74 }
75
76 static void parport_splink_disable_irq(struct parport *p)
77 {
78 DPRINTK(KERN_DEBUG "parport_splink: parport_splink_disable_irq called\n");
79 __parport_splink_frob_control (p, 0x10, 0);
80 }
81
82 static void parport_splink_init_state(struct pardevice *dev, struct parport_state *s)
83 {
84 DPRINTK(KERN_DEBUG "parport_splink: parport_splink_init_state called\n");
85 s->u.pc.ctr = 0xc | (dev->irq_func ? 0x10 : 0x0);
86 if (dev->irq_func &&
87 dev->port->irq != PARPORT_IRQ_NONE)
88 /* Set ackIntEn */
89 s->u.pc.ctr |= 0x10;
90 }
91
92 static void parport_splink_save_state(struct parport *p, struct parport_state *s)
93 {
94 const struct parport_pc_private *priv = p->physport->private_data;
95 DPRINTK(KERN_DEBUG "parport_splink: parport_splink_save_state called\n");
96 s->u.pc.ctr = priv->ctr;
97 }
98
99 static void parport_splink_restore_state(struct parport *p, struct parport_state *s)
100 {
101 struct parport_pc_private *priv = p->physport->private_data;
102 unsigned char *io = (unsigned char *) p->base;
103 unsigned char ctr = s->u.pc.ctr;
104
105 DPRINTK(KERN_DEBUG "parport_splink: parport_splink_restore_state called\n");
106 *(io+2) = ctr;
107 priv->ctr = ctr;
108 }
109
110 static void parport_splink_setup_interrupt(void) {
111 return;
112 }
113
114 static void parport_splink_write_data(struct parport *p, unsigned char d) {
115 DPRINTK(KERN_DEBUG "parport_splink: write data called\n");
116 unsigned char *io = (unsigned char *) p->base;
117 *io = d;
118 }
119
120 static unsigned char parport_splink_read_data(struct parport *p) {
121 DPRINTK(KERN_DEBUG "parport_splink: read data called\n");
122 unsigned char *io = (unsigned char *) p->base;
123 return *io;
124 }
125
126 static void parport_splink_write_control(struct parport *p, unsigned char d)
127 {
128 const unsigned char wm = (PARPORT_CONTROL_STROBE |
129 PARPORT_CONTROL_AUTOFD |
130 PARPORT_CONTROL_INIT |
131 PARPORT_CONTROL_SELECT);
132
133 DPRINTK(KERN_DEBUG "parport_splink: write control called\n");
134 /* Take this out when drivers have adapted to the newer interface. */
135 if (d & 0x20) {
136 printk (KERN_DEBUG "%s (%s): use data_reverse for this!\n",
137 p->name, p->cad->name);
138 parport_splink_data_reverse (p);
139 }
140
141 __parport_splink_frob_control (p, wm, d & wm);
142 }
143
144 static unsigned char parport_splink_read_control(struct parport *p)
145 {
146 const unsigned char wm = (PARPORT_CONTROL_STROBE |
147 PARPORT_CONTROL_AUTOFD |
148 PARPORT_CONTROL_INIT |
149 PARPORT_CONTROL_SELECT);
150 DPRINTK(KERN_DEBUG "parport_splink: read control called\n");
151 const struct parport_pc_private *priv = p->physport->private_data;
152 return priv->ctr & wm; /* Use soft copy */
153 }
154
155 static unsigned char parport_splink_frob_control (struct parport *p, unsigned char mask,
156 unsigned char val)
157 {
158 const unsigned char wm = (PARPORT_CONTROL_STROBE |
159 PARPORT_CONTROL_AUTOFD |
160 PARPORT_CONTROL_INIT |
161 PARPORT_CONTROL_SELECT);
162
163 DPRINTK(KERN_DEBUG "parport_splink: frob control called\n");
164 /* Take this out when drivers have adapted to the newer interface. */
165 if (mask & 0x20) {
166 printk (KERN_DEBUG "%s (%s): use data_%s for this!\n",
167 p->name, p->cad->name,
168 (val & 0x20) ? "reverse" : "forward");
169 if (val & 0x20)
170 parport_splink_data_reverse (p);
171 else
172 parport_splink_data_forward (p);
173 }
174
175 /* Restrict mask and val to control lines. */
176 mask &= wm;
177 val &= wm;
178
179 return __parport_splink_frob_control (p, mask, val);
180 }
181
182 static unsigned char parport_splink_read_status(struct parport *p)
183 {
184 DPRINTK(KERN_DEBUG "parport_splink: read status called\n");
185 unsigned char *io = (unsigned char *) p->base;
186 return *(io+1);
187 }
188
189 static void parport_splink_inc_use_count(void)
190 {
191 #ifdef MODULE
192 MOD_INC_USE_COUNT;
193 #endif
194 }
195
196 static void parport_splink_dec_use_count(void)
197 {
198 #ifdef MODULE
199 MOD_DEC_USE_COUNT;
200 #endif
201 }
202
203 static struct parport_operations parport_splink_ops =
204 {
205 parport_splink_write_data,
206 parport_splink_read_data,
207
208 parport_splink_write_control,
209 parport_splink_read_control,
210 parport_splink_frob_control,
211
212 parport_splink_read_status,
213
214 parport_splink_enable_irq,
215 parport_splink_disable_irq,
216
217 parport_splink_data_forward,
218 parport_splink_data_reverse,
219
220 parport_splink_init_state,
221 parport_splink_save_state,
222 parport_splink_restore_state,
223
224 parport_splink_inc_use_count,
225 parport_splink_dec_use_count,
226
227 parport_ieee1284_epp_write_data,
228 parport_ieee1284_epp_read_data,
229 parport_ieee1284_epp_write_addr,
230 parport_ieee1284_epp_read_addr,
231
232 parport_ieee1284_ecp_write_data,
233 parport_ieee1284_ecp_read_data,
234 parport_ieee1284_ecp_write_addr,
235
236 parport_ieee1284_write_compat,
237 parport_ieee1284_read_nibble,
238 parport_ieee1284_read_byte,
239 };
240
241 /* --- Initialisation code -------------------------------- */
242
243 static struct parport *parport_splink_probe_port (unsigned long int base)
244 {
245 struct parport_pc_private *priv;
246 struct parport_operations *ops;
247 struct parport *p;
248
249 if (check_mem_region(base, 3)) {
250 printk (KERN_DEBUG "parport (0x%lx): iomem region not available\n", base);
251 return NULL;
252 }
253 priv = kmalloc (sizeof (struct parport_pc_private), GFP_KERNEL);
254 if (!priv) {
255 printk (KERN_DEBUG "parport (0x%lx): no memory!\n", base);
256 return NULL;
257 }
258 ops = kmalloc (sizeof (struct parport_operations), GFP_KERNEL);
259 if (!ops) {
260 printk (KERN_DEBUG "parport (0x%lx): no memory for ops!\n",
261 base);
262 kfree (priv);
263 return NULL;
264 }
265 memcpy (ops, &parport_splink_ops, sizeof (struct parport_operations));
266 priv->ctr = 0xc;
267 priv->ctr_writable = 0xff;
268
269 if (!(p = parport_register_port(base, PARPORT_IRQ_NONE,
270 PARPORT_DMA_NONE, ops))) {
271 printk (KERN_DEBUG "parport (0x%lx): registration failed!\n",
272 base);
273 kfree (priv);
274 kfree (ops);
275 return NULL;
276 }
277
278 p->modes = PARPORT_MODE_PCSPP | PARPORT_MODE_SAFEININT;
279 p->size = (p->modes & PARPORT_MODE_EPP)?8:3;
280 p->private_data = priv;
281
282 parport_proc_register(p);
283 request_mem_region (p->base, 3, p->name);
284
285 /* Done probing. Now put the port into a sensible start-up state. */
286 parport_splink_write_data(p, 0);
287 parport_splink_data_forward (p);
288
289 /* Now that we've told the sharing engine about the port, and
290 found out its characteristics, let the high-level drivers
291 know about it. */
292 parport_announce_port (p);
293
294 DPRINTK(KERN_DEBUG "parport (0x%lx): init ok!\n",
295 base);
296 return p;
297 }
298
299 static void parport_splink_unregister_port(struct parport *p) {
300 struct parport_pc_private *priv = p->private_data;
301 struct parport_operations *ops = p->ops;
302
303 if (p->irq != PARPORT_IRQ_NONE)
304 free_irq(p->irq, p);
305 release_mem_region(p->base, 3);
306 parport_proc_unregister(p);
307 kfree (priv);
308 parport_unregister_port(p);
309 kfree (ops);
310 }
311
312
313 int parport_splink_init(void)
314 {
315 int ret;
316
317 DPRINTK(KERN_DEBUG "parport_splink init called\n");
318 parport_splink_setup_interrupt();
319 ret = !parport_splink_probe_port(SPLINK_ADDRESS);
320
321 return ret;
322 }
323
324 void parport_splink_cleanup(void) {
325 struct parport *p = parport_enumerate(), *tmp;
326 DPRINTK(KERN_DEBUG "parport_splink cleanup called\n");
327 if (p->size) {
328 if (p->modes & PARPORT_MODE_PCSPP) {
329 while(p) {
330 tmp = p->next;
331 parport_splink_unregister_port(p);
332 p = tmp;
333 }
334 }
335 }
336 }
337
338 MODULE_AUTHOR("Nuno Grilo <nuno.grilo@netcabo.pt>");
339 MODULE_DESCRIPTION("Parport Driver for ASUS WL-500g router builtin Port");
340 MODULE_SUPPORTED_DEVICE("ASUS WL-500g builtin Parallel Port");
341 MODULE_LICENSE("GPL");
342
343 module_init(parport_splink_init)
344 module_exit(parport_splink_cleanup)
345
This page took 0.093475 seconds and 5 git commands to generate.