Merge git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-2.6-frv
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / parport / parport_atari.c
blob0b28fccec03f4a43ff09811a90db88b5b22bd8a4
1 /* Low-level parallel port routines for the Atari builtin port
3 * Author: Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
5 * Based on parport_amiga.c.
7 * The built-in Atari parallel port provides one port at a fixed address
8 * with 8 output data lines (D0 - D7), 1 output control line (STROBE)
9 * and 1 input status line (BUSY) able to cause an interrupt.
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/parport.h>
15 #include <linux/interrupt.h>
16 #include <asm/setup.h>
17 #include <asm/atarihw.h>
18 #include <asm/irq.h>
19 #include <asm/atariints.h>
21 static struct parport *this_port = NULL;
23 static unsigned char
24 parport_atari_read_data(struct parport *p)
26 unsigned long flags;
27 unsigned char data;
29 local_irq_save(flags);
30 sound_ym.rd_data_reg_sel = 15;
31 data = sound_ym.rd_data_reg_sel;
32 local_irq_restore(flags);
33 return data;
36 static void
37 parport_atari_write_data(struct parport *p, unsigned char data)
39 unsigned long flags;
41 local_irq_save(flags);
42 sound_ym.rd_data_reg_sel = 15;
43 sound_ym.wd_data = data;
44 local_irq_restore(flags);
47 static unsigned char
48 parport_atari_read_control(struct parport *p)
50 unsigned long flags;
51 unsigned char control = 0;
53 local_irq_save(flags);
54 sound_ym.rd_data_reg_sel = 14;
55 if (!(sound_ym.rd_data_reg_sel & (1 << 5)))
56 control = PARPORT_CONTROL_STROBE;
57 local_irq_restore(flags);
58 return control;
61 static void
62 parport_atari_write_control(struct parport *p, unsigned char control)
64 unsigned long flags;
66 local_irq_save(flags);
67 sound_ym.rd_data_reg_sel = 14;
68 if (control & PARPORT_CONTROL_STROBE)
69 sound_ym.wd_data = sound_ym.rd_data_reg_sel & ~(1 << 5);
70 else
71 sound_ym.wd_data = sound_ym.rd_data_reg_sel | (1 << 5);
72 local_irq_restore(flags);
75 static unsigned char
76 parport_atari_frob_control(struct parport *p, unsigned char mask,
77 unsigned char val)
79 unsigned char old = parport_atari_read_control(p);
80 parport_atari_write_control(p, (old & ~mask) ^ val);
81 return old;
84 static unsigned char
85 parport_atari_read_status(struct parport *p)
87 return ((st_mfp.par_dt_reg & 1 ? 0 : PARPORT_STATUS_BUSY) |
88 PARPORT_STATUS_SELECT | PARPORT_STATUS_ERROR);
91 static void
92 parport_atari_init_state(struct pardevice *d, struct parport_state *s)
96 static void
97 parport_atari_save_state(struct parport *p, struct parport_state *s)
101 static void
102 parport_atari_restore_state(struct parport *p, struct parport_state *s)
106 static void
107 parport_atari_enable_irq(struct parport *p)
109 enable_irq(IRQ_MFP_BUSY);
112 static void
113 parport_atari_disable_irq(struct parport *p)
115 disable_irq(IRQ_MFP_BUSY);
118 static void
119 parport_atari_data_forward(struct parport *p)
121 unsigned long flags;
123 local_irq_save(flags);
124 /* Soundchip port B as output. */
125 sound_ym.rd_data_reg_sel = 7;
126 sound_ym.wd_data = sound_ym.rd_data_reg_sel | 0x40;
127 local_irq_restore(flags);
130 static void
131 parport_atari_data_reverse(struct parport *p)
133 #if 0 /* too dangerous, can kill sound chip */
134 unsigned long flags;
136 local_irq_save(flags);
137 /* Soundchip port B as input. */
138 sound_ym.rd_data_reg_sel = 7;
139 sound_ym.wd_data = sound_ym.rd_data_reg_sel & ~0x40;
140 local_irq_restore(flags);
141 #endif
144 static struct parport_operations parport_atari_ops = {
145 .write_data = parport_atari_write_data,
146 .read_data = parport_atari_read_data,
148 .write_control = parport_atari_write_control,
149 .read_control = parport_atari_read_control,
150 .frob_control = parport_atari_frob_control,
152 .read_status = parport_atari_read_status,
154 .enable_irq = parport_atari_enable_irq,
155 .disable_irq = parport_atari_disable_irq,
157 .data_forward = parport_atari_data_forward,
158 .data_reverse = parport_atari_data_reverse,
160 .init_state = parport_atari_init_state,
161 .save_state = parport_atari_save_state,
162 .restore_state = parport_atari_restore_state,
164 .epp_write_data = parport_ieee1284_epp_write_data,
165 .epp_read_data = parport_ieee1284_epp_read_data,
166 .epp_write_addr = parport_ieee1284_epp_write_addr,
167 .epp_read_addr = parport_ieee1284_epp_read_addr,
169 .ecp_write_data = parport_ieee1284_ecp_write_data,
170 .ecp_read_data = parport_ieee1284_ecp_read_data,
171 .ecp_write_addr = parport_ieee1284_ecp_write_addr,
173 .compat_write_data = parport_ieee1284_write_compat,
174 .nibble_read_data = parport_ieee1284_read_nibble,
175 .byte_read_data = parport_ieee1284_read_byte,
177 .owner = THIS_MODULE,
181 static int __init parport_atari_init(void)
183 struct parport *p;
184 unsigned long flags;
186 if (MACH_IS_ATARI) {
187 local_irq_save(flags);
188 /* Soundchip port A/B as output. */
189 sound_ym.rd_data_reg_sel = 7;
190 sound_ym.wd_data = (sound_ym.rd_data_reg_sel & 0x3f) | 0xc0;
191 /* STROBE high. */
192 sound_ym.rd_data_reg_sel = 14;
193 sound_ym.wd_data = sound_ym.rd_data_reg_sel | (1 << 5);
194 local_irq_restore(flags);
195 /* MFP port I0 as input. */
196 st_mfp.data_dir &= ~1;
197 /* MFP port I0 interrupt on high->low edge. */
198 st_mfp.active_edge &= ~1;
199 p = parport_register_port((unsigned long)&sound_ym.wd_data,
200 IRQ_MFP_BUSY, PARPORT_DMA_NONE,
201 &parport_atari_ops);
202 if (!p)
203 return -ENODEV;
204 if (request_irq(IRQ_MFP_BUSY, parport_irq_handler,
205 IRQ_TYPE_SLOW, p->name, p)) {
206 parport_put_port (p);
207 return -ENODEV;
210 this_port = p;
211 printk(KERN_INFO "%s: Atari built-in port using irq\n", p->name);
212 parport_announce_port (p);
214 return 0;
216 return -ENODEV;
219 static void __exit parport_atari_exit(void)
221 parport_remove_port(this_port);
222 if (this_port->irq != PARPORT_IRQ_NONE)
223 free_irq(IRQ_MFP_BUSY, this_port);
224 parport_put_port(this_port);
227 MODULE_AUTHOR("Andreas Schwab");
228 MODULE_DESCRIPTION("Parport Driver for Atari builtin Port");
229 MODULE_SUPPORTED_DEVICE("Atari builtin Parallel Port");
230 MODULE_LICENSE("GPL");
232 module_init(parport_atari_init)
233 module_exit(parport_atari_exit)