1 /* $Id: parport_sunbpp.c,v 1.7 1999/09/02 11:59:31 davem Exp $
2 * Parallel-port routines for Sun architecture
4 * Author: Derrick J. Brashear <shadow@dementia.org>
7 * Phil Blundell <Philip.Blundell@pobox.com>
8 * Tim Waugh <tim@cyberelk.demon.co.uk>
9 * Jose Renau <renau@acm.org>
10 * David Campbell <campbell@tirian.che.curtin.edu.au>
11 * Grant Guenther <grant@torque.net>
12 * Eddie C. Dost <ecd@skynet.be>
13 * Stephen Williams (steve@icarus.com)
14 * Gus Baldauf (gbaldauf@ix.netcom.com)
19 #include <linux/string.h>
20 #include <linux/module.h>
21 #include <linux/delay.h>
22 #include <linux/errno.h>
23 #include <linux/ioport.h>
24 #include <linux/kernel.h>
25 #include <linux/malloc.h>
26 #include <linux/init.h>
28 #include <linux/parport.h>
30 #include <asm/ptrace.h>
31 #include <linux/interrupt.h>
34 #include <asm/oplib.h> /* OpenProm Library */
35 #include <asm/sbus.h> /* struct linux_sbus *SBus_chain */
36 #include <asm/dma.h> /* BPP uses LSI 64854 for DMA */
38 #include <asm/sunbpp.h>
42 #define dprintk(x) printk x
47 static void parport_sunbpp_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
49 parport_generic_irq(irq
, (struct parport
*) dev_id
, regs
);
52 static void parport_sunbpp_disable_irq(struct parport
*p
)
54 struct bpp_regs
*regs
= (struct bpp_regs
*)p
->base
;
56 regs
->p_csr
&= ~(DMA_INT_ENAB
);
59 static void parport_sunbpp_enable_irq(struct parport
*p
)
61 struct bpp_regs
*regs
= (struct bpp_regs
*)p
->base
;
63 regs
->p_csr
|= DMA_INT_ENAB
;
66 static void parport_sunbpp_write_data(struct parport
*p
, unsigned char d
)
68 struct bpp_regs
*regs
= (struct bpp_regs
*)p
->base
;
71 dprintk(("wrote 0x%x\n", d
));
74 static unsigned char parport_sunbpp_read_data(struct parport
*p
)
76 struct bpp_regs
*regs
= (struct bpp_regs
*)p
->base
;
81 static void control_pc_to_sunbpp(struct parport
*p
, unsigned char status
)
83 struct bpp_regs
*regs
= (struct bpp_regs
*)p
->base
;
84 unsigned char value_tcr
= regs
->p_tcr
;
85 unsigned char value_or
= regs
->p_or
;
87 if (status
& PARPORT_CONTROL_STROBE
)
88 value_tcr
|= P_TCR_DS
;
89 if (status
& PARPORT_CONTROL_AUTOFD
)
90 value_or
|= P_OR_AFXN
;
91 if (status
& PARPORT_CONTROL_INIT
)
92 value_or
|= P_OR_INIT
;
93 if (status
& PARPORT_CONTROL_SELECT
)
94 value_or
|= P_OR_SLCT_IN
;
96 regs
->p_or
= value_or
;
97 regs
->p_tcr
= value_tcr
;
100 static unsigned char status_sunbpp_to_pc(struct parport
*p
)
102 struct bpp_regs
*regs
= (struct bpp_regs
*)p
->base
;
103 unsigned char bits
= 0;
104 unsigned char value_tcr
= regs
->p_tcr
;
105 unsigned char value_ir
= regs
->p_ir
;
107 if (!(value_ir
& P_IR_ERR
))
108 bits
|= PARPORT_STATUS_ERROR
;
109 if (!(value_ir
& P_IR_SLCT
))
110 bits
|= PARPORT_STATUS_SELECT
;
111 if (!(value_ir
& P_IR_PE
))
112 bits
|= PARPORT_STATUS_PAPEROUT
;
113 if (value_tcr
& P_TCR_ACK
)
114 bits
|= PARPORT_STATUS_ACK
;
115 if (!(value_tcr
& P_TCR_BUSY
))
116 bits
|= PARPORT_STATUS_BUSY
;
118 dprintk(("tcr 0x%x ir 0x%x\n", regs
->p_tcr
, regs
->p_ir
));
119 dprintk(("read status 0x%x\n", bits
));
123 static unsigned char control_sunbpp_to_pc(struct parport
*p
)
125 struct bpp_regs
*regs
= (struct bpp_regs
*)p
->base
;
126 unsigned char bits
= 0;
127 unsigned char value_tcr
= regs
->p_tcr
;
128 unsigned char value_or
= regs
->p_or
;
130 if (!(value_tcr
& P_TCR_DS
))
131 bits
|= PARPORT_CONTROL_STROBE
;
132 if (!(value_or
& P_OR_AFXN
))
133 bits
|= PARPORT_CONTROL_AUTOFD
;
134 if (!(value_or
& P_OR_INIT
))
135 bits
|= PARPORT_CONTROL_INIT
;
136 if (value_or
& P_OR_SLCT_IN
)
137 bits
|= PARPORT_CONTROL_SELECT
;
139 dprintk(("tcr 0x%x or 0x%x\n", regs
->p_tcr
, regs
->p_or
));
140 dprintk(("read control 0x%x\n", bits
));
144 static unsigned char parport_sunbpp_read_control(struct parport
*p
)
146 return control_sunbpp_to_pc(p
);
149 static unsigned char parport_sunbpp_frob_control(struct parport
*p
,
153 struct bpp_regs
*regs
= (struct bpp_regs
*)p
->base
;
154 unsigned char value_tcr
= regs
->p_tcr
;
155 unsigned char value_or
= regs
->p_or
;
157 dprintk(("frob1: tcr 0x%x or 0x%x\n", regs
->p_tcr
, regs
->p_or
));
158 if (mask
& PARPORT_CONTROL_STROBE
) {
159 if (val
& PARPORT_CONTROL_STROBE
) {
160 value_tcr
&= ~P_TCR_DS
;
162 value_tcr
|= P_TCR_DS
;
165 if (mask
& PARPORT_CONTROL_AUTOFD
) {
166 if (val
& PARPORT_CONTROL_AUTOFD
) {
167 value_or
&= ~P_OR_AFXN
;
169 value_or
|= P_OR_AFXN
;
172 if (mask
& PARPORT_CONTROL_INIT
) {
173 if (val
& PARPORT_CONTROL_INIT
) {
174 value_or
&= ~P_OR_INIT
;
176 value_or
|= P_OR_INIT
;
179 if (mask
& PARPORT_CONTROL_SELECT
) {
180 if (val
& PARPORT_CONTROL_SELECT
) {
181 value_or
|= P_OR_SLCT_IN
;
183 value_or
&= ~P_OR_SLCT_IN
;
187 regs
->p_or
= value_or
;
188 regs
->p_tcr
= value_tcr
;
189 dprintk(("frob2: tcr 0x%x or 0x%x\n", regs
->p_tcr
, regs
->p_or
));
190 return parport_sunbpp_read_control(p
);
193 static void parport_sunbpp_write_control(struct parport
*p
, unsigned char d
)
195 const unsigned char wm
= (PARPORT_CONTROL_STROBE
|
196 PARPORT_CONTROL_AUTOFD
|
197 PARPORT_CONTROL_INIT
|
198 PARPORT_CONTROL_SELECT
);
200 parport_sunbpp_frob_control (p
, wm
, d
& wm
);
203 static unsigned char parport_sunbpp_read_status(struct parport
*p
)
205 return status_sunbpp_to_pc(p
);
208 static void parport_sunbpp_data_forward (struct parport
*p
)
210 struct bpp_regs
*regs
= (struct bpp_regs
*)p
->base
;
211 unsigned char value_tcr
= regs
->p_tcr
;
213 dprintk(("forward\n"));
214 value_tcr
= regs
->p_tcr
;
215 value_tcr
&= ~P_TCR_DIR
;
216 regs
->p_tcr
= value_tcr
;
219 static void parport_sunbpp_data_reverse (struct parport
*p
)
221 struct bpp_regs
*regs
= (struct bpp_regs
*)p
->base
;
223 dprintk(("reverse\n"));
224 regs
->p_tcr
|= P_TCR_DIR
;
227 static void parport_sunbpp_init_state(struct pardevice
*dev
, struct parport_state
*s
)
233 static void parport_sunbpp_save_state(struct parport
*p
, struct parport_state
*s
)
235 s
->u
.pc
.ctr
= parport_sunbpp_read_control(p
);
238 static void parport_sunbpp_restore_state(struct parport
*p
, struct parport_state
*s
)
240 parport_sunbpp_write_control(p
, s
->u
.pc
.ctr
);
243 static void parport_sunbpp_inc_use_count(void)
250 static void parport_sunbpp_dec_use_count(void)
257 static struct parport_operations parport_sunbpp_ops
=
259 parport_sunbpp_write_data
,
260 parport_sunbpp_read_data
,
262 parport_sunbpp_write_control
,
263 parport_sunbpp_read_control
,
264 parport_sunbpp_frob_control
,
266 parport_sunbpp_read_status
,
268 parport_sunbpp_enable_irq
,
269 parport_sunbpp_disable_irq
,
271 parport_sunbpp_data_forward
,
272 parport_sunbpp_data_reverse
,
274 parport_sunbpp_init_state
,
275 parport_sunbpp_save_state
,
276 parport_sunbpp_restore_state
,
278 parport_sunbpp_inc_use_count
,
279 parport_sunbpp_dec_use_count
,
281 parport_ieee1284_epp_write_data
,
282 parport_ieee1284_epp_read_data
,
283 parport_ieee1284_epp_write_addr
,
284 parport_ieee1284_epp_read_addr
,
286 parport_ieee1284_ecp_write_data
,
287 parport_ieee1284_ecp_read_data
,
288 parport_ieee1284_ecp_write_addr
,
290 parport_ieee1284_write_compat
,
291 parport_ieee1284_read_nibble
,
292 parport_ieee1284_read_byte
,
295 static int __init
init_one_port(struct linux_sbus_device
*sdev
)
298 /* at least in theory there may be a "we don't dma" case */
299 struct parport_operations
*ops
;
301 int irq
, dma
, err
, size
;
302 struct bpp_regs
*regs
;
303 unsigned char value_tcr
;
305 dprintk(("init_one_port(%p): ranges, alloc_io, ", sdev
));
307 prom_apply_sbus_ranges(sdev
->my_bus
, sdev
->reg_addrs
, 1, sdev
);
308 base
= sparc_alloc_io(sdev
->reg_addrs
[0].phys_addr
, 0,
309 sdev
->reg_addrs
[0].reg_size
,
310 "sunbpp", sdev
->reg_addrs
[0].which_io
, 0);
311 size
= sdev
->reg_addrs
[0].reg_size
;
312 dma
= PARPORT_DMA_NONE
;
314 dprintk(("alloc(ppops), "));
315 ops
= kmalloc (sizeof (struct parport_operations
), GFP_KERNEL
);
317 sparc_free_io(base
, size
);
321 memcpy (ops
, &parport_sunbpp_ops
, sizeof (struct parport_operations
));
323 dprintk(("register_port, "));
324 if (!(p
= parport_register_port((unsigned long)base
, irq
, dma
, ops
))) {
326 sparc_free_io(base
, size
);
330 dprintk(("init_one_port: request_irq(%08x:%p:%x:%s:%p) ",
331 p
->irq
, parport_sunbpp_interrupt
, SA_SHIRQ
, p
->name
, p
));
332 if ((err
= request_irq(p
->irq
, parport_sunbpp_interrupt
,
333 SA_SHIRQ
, p
->name
, p
)) != 0) {
334 dprintk(("ERROR %d\n", err
));
335 parport_unregister_port(p
);
337 sparc_free_io(base
, size
);
341 parport_sunbpp_enable_irq(p
);
344 regs
= (struct bpp_regs
*)p
->base
;
345 dprintk(("forward\n"));
346 value_tcr
= regs
->p_tcr
;
347 value_tcr
&= ~P_TCR_DIR
;
348 regs
->p_tcr
= value_tcr
;
350 printk(KERN_INFO
"%s: sunbpp at 0x%lx\n", p
->name
, p
->base
);
351 parport_proc_register(p
);
352 parport_announce_port (p
);
360 int init_module(void)
362 int __init
parport_sunbpp_init(void)
365 struct linux_sbus
*sbus
;
366 struct linux_sbus_device
*sdev
;
369 for_each_sbus(sbus
) {
370 for_each_sbusdev(sdev
, sbus
) {
371 if (!strcmp(sdev
->prom_name
, "SUNW,bpp"))
372 count
+= init_one_port(sdev
);
375 return count
? 0 : -ENODEV
;
379 MODULE_AUTHOR("Derrick J Brashear");
380 MODULE_DESCRIPTION("Parport Driver for Sparc bidirectional Port");
381 MODULE_SUPPORTED_DEVICE("Sparc Bidirectional Parallel Port");
386 struct parport
*p
= parport_enumerate(), *tmp
;
389 if (1/*p->modes & PARPORT_MODE_PCSPP*/) {
390 struct parport_operations
*ops
= p
->ops
;
391 if (p
->irq
!= PARPORT_IRQ_NONE
) {
392 parport_sunbpp_disable_irq(p
);
395 sparc_free_io((char *)p
->base
, p
->size
);
396 parport_proc_unregister(p
);
397 parport_unregister_port(p
);