1 /* Low-level parallel port routines for the ASUS WL-500g built-in port
3 * Author: Nuno Grilo <nuno.grilo@netcabo.pt>
4 * Based on parport_pc source
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>
16 #define SPLINK_ADDRESS 0xBF800010
21 #define DPRINTK printk
23 #define DPRINTK(stuff...)
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
,
33 struct parport_pc_private
*priv
= p
->physport
->private_data
;
34 unsigned char *io
= (unsigned char *) p
->base
;
35 unsigned char ctr
= priv
->ctr
;
38 "__parport_splink_frob_control(%02x,%02x): %02x -> %02x\n",
39 mask
, val
, ctr
, ((ctr
& ~mask
) ^ val
) & priv
->ctr_writable
);
41 ctr
= (ctr
& ~mask
) ^ val
;
42 ctr
&= priv
->ctr_writable
; /* only write writable bits. */
44 priv
->ctr
= ctr
; /* Update soft copy */
50 static void parport_splink_data_forward (struct parport
*p
)
52 DPRINTK(KERN_DEBUG
"parport_splink: parport_data_forward called\n");
53 __parport_splink_frob_control (p
, 0x20, 0);
56 static void parport_splink_data_reverse (struct parport
*p
)
58 DPRINTK(KERN_DEBUG
"parport_splink: parport_data_forward called\n");
59 __parport_splink_frob_control (p
, 0x20, 0x20);
63 static void parport_splink_interrupt(int irq, void *dev_id, struct pt_regs *regs)
65 DPRINTK(KERN_DEBUG "parport_splink: IRQ handler called\n");
66 parport_generic_irq(irq, (struct parport *) dev_id, regs);
70 static void parport_splink_enable_irq(struct parport
*p
)
72 DPRINTK(KERN_DEBUG
"parport_splink: parport_splink_enable_irq called\n");
73 __parport_splink_frob_control (p
, 0x10, 0x10);
76 static void parport_splink_disable_irq(struct parport
*p
)
78 DPRINTK(KERN_DEBUG
"parport_splink: parport_splink_disable_irq called\n");
79 __parport_splink_frob_control (p
, 0x10, 0);
82 static void parport_splink_init_state(struct pardevice
*dev
, struct parport_state
*s
)
84 DPRINTK(KERN_DEBUG
"parport_splink: parport_splink_init_state called\n");
85 s
->u
.pc
.ctr
= 0xc | (dev
->irq_func
? 0x10 : 0x0);
87 dev
->port
->irq
!= PARPORT_IRQ_NONE
)
92 static void parport_splink_save_state(struct parport
*p
, struct parport_state
*s
)
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
;
99 static void parport_splink_restore_state(struct parport
*p
, struct parport_state
*s
)
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
;
105 DPRINTK(KERN_DEBUG
"parport_splink: parport_splink_restore_state called\n");
110 static void parport_splink_setup_interrupt(void) {
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
;
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
;
126 static void parport_splink_write_control(struct parport
*p
, unsigned char d
)
128 const unsigned char wm
= (PARPORT_CONTROL_STROBE
|
129 PARPORT_CONTROL_AUTOFD
|
130 PARPORT_CONTROL_INIT
|
131 PARPORT_CONTROL_SELECT
);
133 DPRINTK(KERN_DEBUG
"parport_splink: write control called\n");
134 /* Take this out when drivers have adapted to the newer interface. */
136 printk (KERN_DEBUG
"%s (%s): use data_reverse for this!\n",
137 p
->name
, p
->cad
->name
);
138 parport_splink_data_reverse (p
);
141 __parport_splink_frob_control (p
, wm
, d
& wm
);
144 static unsigned char parport_splink_read_control(struct parport
*p
)
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 */
155 static unsigned char parport_splink_frob_control (struct parport
*p
, unsigned char mask
,
158 const unsigned char wm
= (PARPORT_CONTROL_STROBE
|
159 PARPORT_CONTROL_AUTOFD
|
160 PARPORT_CONTROL_INIT
|
161 PARPORT_CONTROL_SELECT
);
163 DPRINTK(KERN_DEBUG
"parport_splink: frob control called\n");
164 /* Take this out when drivers have adapted to the newer interface. */
166 printk (KERN_DEBUG
"%s (%s): use data_%s for this!\n",
167 p
->name
, p
->cad
->name
,
168 (val
& 0x20) ? "reverse" : "forward");
170 parport_splink_data_reverse (p
);
172 parport_splink_data_forward (p
);
175 /* Restrict mask and val to control lines. */
179 return __parport_splink_frob_control (p
, mask
, val
);
182 static unsigned char parport_splink_read_status(struct parport
*p
)
184 DPRINTK(KERN_DEBUG
"parport_splink: read status called\n");
185 unsigned char *io
= (unsigned char *) p
->base
;
189 static void parport_splink_inc_use_count(void)
196 static void parport_splink_dec_use_count(void)
203 static struct parport_operations parport_splink_ops
=
205 parport_splink_write_data
,
206 parport_splink_read_data
,
208 parport_splink_write_control
,
209 parport_splink_read_control
,
210 parport_splink_frob_control
,
212 parport_splink_read_status
,
214 parport_splink_enable_irq
,
215 parport_splink_disable_irq
,
217 parport_splink_data_forward
,
218 parport_splink_data_reverse
,
220 parport_splink_init_state
,
221 parport_splink_save_state
,
222 parport_splink_restore_state
,
224 parport_splink_inc_use_count
,
225 parport_splink_dec_use_count
,
227 parport_ieee1284_epp_write_data
,
228 parport_ieee1284_epp_read_data
,
229 parport_ieee1284_epp_write_addr
,
230 parport_ieee1284_epp_read_addr
,
232 parport_ieee1284_ecp_write_data
,
233 parport_ieee1284_ecp_read_data
,
234 parport_ieee1284_ecp_write_addr
,
236 parport_ieee1284_write_compat
,
237 parport_ieee1284_read_nibble
,
238 parport_ieee1284_read_byte
,
241 /* --- Initialisation code -------------------------------- */
243 static struct parport
*parport_splink_probe_port (unsigned long int base
)
245 struct parport_pc_private
*priv
;
246 struct parport_operations
*ops
;
249 if (check_mem_region(base
, 3)) {
250 printk (KERN_DEBUG
"parport (0x%lx): iomem region not available\n", base
);
253 priv
= kmalloc (sizeof (struct parport_pc_private
), GFP_KERNEL
);
255 printk (KERN_DEBUG
"parport (0x%lx): no memory!\n", base
);
258 ops
= kmalloc (sizeof (struct parport_operations
), GFP_KERNEL
);
260 printk (KERN_DEBUG
"parport (0x%lx): no memory for ops!\n",
265 memcpy (ops
, &parport_splink_ops
, sizeof (struct parport_operations
));
267 priv
->ctr_writable
= 0xff;
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",
278 p
->modes
= PARPORT_MODE_PCSPP
| PARPORT_MODE_SAFEININT
;
279 p
->size
= (p
->modes
& PARPORT_MODE_EPP
)?8:3;
280 p
->private_data
= priv
;
282 parport_proc_register(p
);
283 request_mem_region (p
->base
, 3, p
->name
);
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
);
289 /* Now that we've told the sharing engine about the port, and
290 found out its characteristics, let the high-level drivers
292 parport_announce_port (p
);
294 DPRINTK(KERN_DEBUG
"parport (0x%lx): init ok!\n",
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
;
303 if (p
->irq
!= PARPORT_IRQ_NONE
)
305 release_mem_region(p
->base
, 3);
306 parport_proc_unregister(p
);
308 parport_unregister_port(p
);
313 int parport_splink_init(void)
317 DPRINTK(KERN_DEBUG
"parport_splink init called\n");
318 parport_splink_setup_interrupt();
319 ret
= !parport_splink_probe_port(SPLINK_ADDRESS
);
324 void parport_splink_cleanup(void) {
325 struct parport
*p
= parport_enumerate(), *tmp
;
326 DPRINTK(KERN_DEBUG
"parport_splink cleanup called\n");
328 if (p
->modes
& PARPORT_MODE_PCSPP
) {
331 parport_splink_unregister_port(p
);
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");
343 module_init(parport_splink_init
)
344 module_exit(parport_splink_cleanup
)