1 /* Low-level parallel port routines for Archimedes onboard hardware
2  *
3  * Author: Phil Blundell <philb@gnu.org>
4  */
5 
6 /* This driver is for the parallel port hardware found on Acorn's old
7  * range of Archimedes machines.  The A5000 and newer systems have PC-style
8  * I/O hardware and should use the parport_pc driver instead.
9  *
10  * The Acorn printer port hardware is very simple.  There is a single 8-bit
11  * write-only latch for the data port and control/status bits are handled
12  * with various auxilliary input and output lines.  The port is not
13  * bidirectional, does not support any modes other than SPP, and has only
14  * a subset of the standard printer control lines connected.
15  */
16 
17 #include <linux/threads.h>
18 #include <linux/delay.h>
19 #include <linux/errno.h>
20 #include <linux/interrupt.h>
21 #include <linux/ioport.h>
22 #include <linux/kernel.h>
23 #include <linux/slab.h>
24 #include <linux/parport.h>
25 
26 #include <asm/ptrace.h>
27 #include <asm/io.h>
28 #include <asm/arch/oldlatches.h>
29 #include <asm/arch/irqs.h>
30 
31 #define DATA_ADDRESS    0x3350010
32 
33 /* This is equivalent to the above and only used for request_region. */
34 #define PORT_BASE       0x80000000 | ((DATA_ADDRESS - IO_BASE) >> 2)
35 
36 /* The hardware can't read from the data latch, so we must use a soft
37    copy. */
38 static unsigned char data_copy;
39 
40 /* These are pretty simple. We know the irq is never shared and the
41    kernel does all the magic that's required. */
arc_enable_irq(struct parport * p)42 static void arc_enable_irq(struct parport *p)
43 {
44 	enable_irq(p->irq);
45 }
46 
arc_disable_irq(struct parport * p)47 static void arc_disable_irq(struct parport *p)
48 {
49 	disable_irq(p->irq);
50 }
51 
arc_interrupt(int irq,void * dev_id,struct pt_regs * regs)52 static void arc_interrupt(int irq, void *dev_id, struct pt_regs *regs)
53 {
54 	parport_generic_irq(irq, (struct parport *) dev_id, regs);
55 }
56 
arc_write_data(struct parport * p,unsigned char data)57 static void arc_write_data(struct parport *p, unsigned char data)
58 {
59 	data_copy = data;
60 	outb_t(data, DATA_LATCH);
61 }
62 
arc_read_data(struct parport * p)63 static unsigned char arc_read_data(struct parport *p)
64 {
65 	return data_copy;
66 }
67 
arc_inc_use_count(void)68 static void arc_inc_use_count(void)
69 {
70 #ifdef MODULE
71 	MOD_INC_USE_COUNT;
72 #endif
73 }
74 
arc_dec_use_count(void)75 static void arc_dec_use_count(void)
76 {
77 #ifdef MODULE
78 	MOD_DEC_USE_COUNT;
79 #endif
80 }
81 
82 static struct parport_operations parport_arc_ops =
83 {
84 	arc_write_data,
85 	arc_read_data,
86 
87 	arc_write_control,
88 	arc_read_control,
89 	arc_frob_control,
90 
91 	arc_read_status,
92 
93 	arc_enable_irq,
94 	arc_disable_irq,
95 
96 	arc_data_forward,
97 	arc_data_reverse,
98 
99 	arc_init_state,
100 	arc_save_state,
101 	arc_restore_state,
102 
103 	arc_inc_use_count,
104 	arc_dec_use_count,
105 
106 	parport_ieee1284_epp_write_data,
107 	parport_ieee1284_epp_read_data,
108 	parport_ieee1284_epp_write_addr,
109 	parport_ieee1284_epp_read_addr,
110 
111 	parport_ieee1284_ecp_write_data,
112 	parport_ieee1284_ecp_read_data,
113 	parport_ieee1284_ecp_write_addr,
114 
115 	parport_ieee1284_write_compat,
116 	parport_ieee1284_read_nibble,
117 	parport_ieee1284_read_byte,
118 };
119 
120 /* --- Initialisation code -------------------------------- */
121 
parport_arc_init(void)122 int parport_arc_init(void)
123 {
124 	/* Archimedes hardware provides only one port, at a fixed address */
125 	struct parport *p;
126 
127 	if (check_region(PORT_BASE, 1))
128 		return 0;
129 
130 	p = parport_register_port (PORT_BASE, IRQ_PRINTERACK,
131 				   PARPORT_DMA_NONE, &parport_arc_ops);
132 
133 	if (!p)
134 		return 0;
135 
136 	p->modes = PARPORT_MODE_ARCSPP;
137 	p->size = 1;
138 
139 	printk(KERN_INFO "%s: Archimedes on-board port, using irq %d\n",
140 	       p->irq);
141 	parport_proc_register(p);
142 
143 	/* Tell the high-level drivers about the port. */
144 	parport_announce_port (p);
145 
146 	return 1;
147 }
148