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>
19 #include <asm/atariints.h>
21 static struct parport
*this_port
= NULL
;
24 parport_atari_read_data(struct parport
*p
)
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
);
37 parport_atari_write_data(struct parport
*p
, unsigned char data
)
41 local_irq_save(flags
);
42 sound_ym
.rd_data_reg_sel
= 15;
43 sound_ym
.wd_data
= data
;
44 local_irq_restore(flags
);
48 parport_atari_read_control(struct parport
*p
)
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
);
62 parport_atari_write_control(struct parport
*p
, unsigned char control
)
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);
71 sound_ym
.wd_data
= sound_ym
.rd_data_reg_sel
| (1 << 5);
72 local_irq_restore(flags
);
76 parport_atari_frob_control(struct parport
*p
, unsigned char mask
,
79 unsigned char old
= parport_atari_read_control(p
);
80 parport_atari_write_control(p
, (old
& ~mask
) ^ val
);
85 parport_atari_read_status(struct parport
*p
)
87 return ((mfp
.par_dt_reg
& 1 ? 0 : PARPORT_STATUS_BUSY
) |
88 PARPORT_STATUS_SELECT
| PARPORT_STATUS_ERROR
);
92 parport_atari_init_state(struct pardevice
*d
, struct parport_state
*s
)
97 parport_atari_save_state(struct parport
*p
, struct parport_state
*s
)
102 parport_atari_restore_state(struct parport
*p
, struct parport_state
*s
)
107 parport_atari_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
109 parport_generic_irq(irq
, (struct parport
*) dev_id
, regs
);
114 parport_atari_enable_irq(struct parport
*p
)
116 enable_irq(IRQ_MFP_BUSY
);
120 parport_atari_disable_irq(struct parport
*p
)
122 disable_irq(IRQ_MFP_BUSY
);
126 parport_atari_data_forward(struct parport
*p
)
130 local_irq_save(flags
);
131 /* Soundchip port B as output. */
132 sound_ym
.rd_data_reg_sel
= 7;
133 sound_ym
.wd_data
= sound_ym
.rd_data_reg_sel
| 0x40;
134 local_irq_restore(flags
);
138 parport_atari_data_reverse(struct parport
*p
)
140 #if 0 /* too dangerous, can kill sound chip */
143 local_irq_save(flags
);
144 /* Soundchip port B as input. */
145 sound_ym
.rd_data_reg_sel
= 7;
146 sound_ym
.wd_data
= sound_ym
.rd_data_reg_sel
& ~0x40;
147 local_irq_restore(flags
);
151 static struct parport_operations parport_atari_ops
= {
152 .write_data
= parport_atari_write_data
,
153 .read_data
= parport_atari_read_data
,
155 .write_control
= parport_atari_write_control
,
156 .read_control
= parport_atari_read_control
,
157 .frob_control
= parport_atari_frob_control
,
159 .read_status
= parport_atari_read_status
,
161 .enable_irq
= parport_atari_enable_irq
,
162 .disable_irq
= parport_atari_disable_irq
,
164 .data_forward
= parport_atari_data_forward
,
165 .data_reverse
= parport_atari_data_reverse
,
167 .init_state
= parport_atari_init_state
,
168 .save_state
= parport_atari_save_state
,
169 .restore_state
= parport_atari_restore_state
,
171 .epp_write_data
= parport_ieee1284_epp_write_data
,
172 .epp_read_data
= parport_ieee1284_epp_read_data
,
173 .epp_write_addr
= parport_ieee1284_epp_write_addr
,
174 .epp_read_addr
= parport_ieee1284_epp_read_addr
,
176 .ecp_write_data
= parport_ieee1284_ecp_write_data
,
177 .ecp_read_data
= parport_ieee1284_ecp_read_data
,
178 .ecp_write_addr
= parport_ieee1284_ecp_write_addr
,
180 .compat_write_data
= parport_ieee1284_write_compat
,
181 .nibble_read_data
= parport_ieee1284_read_nibble
,
182 .byte_read_data
= parport_ieee1284_read_byte
,
184 .owner
= THIS_MODULE
,
188 static int __init
parport_atari_init(void)
194 local_irq_save(flags
);
195 /* Soundchip port A/B as output. */
196 sound_ym
.rd_data_reg_sel
= 7;
197 sound_ym
.wd_data
= (sound_ym
.rd_data_reg_sel
& 0x3f) | 0xc0;
199 sound_ym
.rd_data_reg_sel
= 14;
200 sound_ym
.wd_data
= sound_ym
.rd_data_reg_sel
| (1 << 5);
201 local_irq_restore(flags
);
202 /* MFP port I0 as input. */
204 /* MFP port I0 interrupt on high->low edge. */
205 mfp
.active_edge
&= ~1;
206 p
= parport_register_port((unsigned long)&sound_ym
.wd_data
,
207 IRQ_MFP_BUSY
, PARPORT_DMA_NONE
,
211 if (request_irq(IRQ_MFP_BUSY
, parport_atari_interrupt
,
212 IRQ_TYPE_SLOW
, p
->name
, p
)) {
213 parport_put_port (p
);
218 printk(KERN_INFO
"%s: Atari built-in port using irq\n", p
->name
);
219 parport_announce_port (p
);
226 static void __exit
parport_atari_exit(void)
228 parport_remove_port(this_port
);
229 if (this_port
->irq
!= PARPORT_IRQ_NONE
)
230 free_irq(IRQ_MFP_BUSY
, this_port
);
231 parport_put_port(this_port
);
234 MODULE_AUTHOR("Andreas Schwab");
235 MODULE_DESCRIPTION("Parport Driver for Atari builtin Port");
236 MODULE_SUPPORTED_DEVICE("Atari builtin Parallel Port");
237 MODULE_LICENSE("GPL");
239 module_init(parport_atari_init
)
240 module_exit(parport_atari_exit
)