1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Low-level parallel port routines for the Atari builtin port
4 * Author: Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
6 * Based on parport_amiga.c.
8 * The built-in Atari parallel port provides one port at a fixed address
9 * with 8 output data lines (D0 - D7), 1 output control line (STROBE)
10 * and 1 input status line (BUSY) able to cause an interrupt.
13 #include <linux/module.h>
14 #include <linux/init.h>
15 #include <linux/parport.h>
16 #include <linux/interrupt.h>
17 #include <asm/setup.h>
18 #include <asm/atarihw.h>
20 #include <asm/atariints.h>
22 static struct parport
*this_port
;
25 parport_atari_read_data(struct parport
*p
)
30 local_irq_save(flags
);
31 sound_ym
.rd_data_reg_sel
= 15;
32 data
= sound_ym
.rd_data_reg_sel
;
33 local_irq_restore(flags
);
38 parport_atari_write_data(struct parport
*p
, unsigned char data
)
42 local_irq_save(flags
);
43 sound_ym
.rd_data_reg_sel
= 15;
44 sound_ym
.wd_data
= data
;
45 local_irq_restore(flags
);
49 parport_atari_read_control(struct parport
*p
)
52 unsigned char control
= 0;
54 local_irq_save(flags
);
55 sound_ym
.rd_data_reg_sel
= 14;
56 if (!(sound_ym
.rd_data_reg_sel
& (1 << 5)))
57 control
= PARPORT_CONTROL_STROBE
;
58 local_irq_restore(flags
);
63 parport_atari_write_control(struct parport
*p
, unsigned char control
)
67 local_irq_save(flags
);
68 sound_ym
.rd_data_reg_sel
= 14;
69 if (control
& PARPORT_CONTROL_STROBE
)
70 sound_ym
.wd_data
= sound_ym
.rd_data_reg_sel
& ~(1 << 5);
72 sound_ym
.wd_data
= sound_ym
.rd_data_reg_sel
| (1 << 5);
73 local_irq_restore(flags
);
77 parport_atari_frob_control(struct parport
*p
, unsigned char mask
,
80 unsigned char old
= parport_atari_read_control(p
);
81 parport_atari_write_control(p
, (old
& ~mask
) ^ val
);
86 parport_atari_read_status(struct parport
*p
)
88 return ((st_mfp
.par_dt_reg
& 1 ? 0 : PARPORT_STATUS_BUSY
) |
89 PARPORT_STATUS_SELECT
| PARPORT_STATUS_ERROR
);
93 parport_atari_init_state(struct pardevice
*d
, struct parport_state
*s
)
98 parport_atari_save_state(struct parport
*p
, struct parport_state
*s
)
103 parport_atari_restore_state(struct parport
*p
, struct parport_state
*s
)
108 parport_atari_enable_irq(struct parport
*p
)
110 enable_irq(IRQ_MFP_BUSY
);
114 parport_atari_disable_irq(struct parport
*p
)
116 disable_irq(IRQ_MFP_BUSY
);
120 parport_atari_data_forward(struct parport
*p
)
124 local_irq_save(flags
);
125 /* Soundchip port B as output. */
126 sound_ym
.rd_data_reg_sel
= 7;
127 sound_ym
.wd_data
= sound_ym
.rd_data_reg_sel
| 0x40;
128 local_irq_restore(flags
);
132 parport_atari_data_reverse(struct parport
*p
)
136 static struct parport_operations parport_atari_ops
= {
137 .write_data
= parport_atari_write_data
,
138 .read_data
= parport_atari_read_data
,
140 .write_control
= parport_atari_write_control
,
141 .read_control
= parport_atari_read_control
,
142 .frob_control
= parport_atari_frob_control
,
144 .read_status
= parport_atari_read_status
,
146 .enable_irq
= parport_atari_enable_irq
,
147 .disable_irq
= parport_atari_disable_irq
,
149 .data_forward
= parport_atari_data_forward
,
150 .data_reverse
= parport_atari_data_reverse
,
152 .init_state
= parport_atari_init_state
,
153 .save_state
= parport_atari_save_state
,
154 .restore_state
= parport_atari_restore_state
,
156 .epp_write_data
= parport_ieee1284_epp_write_data
,
157 .epp_read_data
= parport_ieee1284_epp_read_data
,
158 .epp_write_addr
= parport_ieee1284_epp_write_addr
,
159 .epp_read_addr
= parport_ieee1284_epp_read_addr
,
161 .ecp_write_data
= parport_ieee1284_ecp_write_data
,
162 .ecp_read_data
= parport_ieee1284_ecp_read_data
,
163 .ecp_write_addr
= parport_ieee1284_ecp_write_addr
,
165 .compat_write_data
= parport_ieee1284_write_compat
,
166 .nibble_read_data
= parport_ieee1284_read_nibble
,
167 .byte_read_data
= parport_ieee1284_read_byte
,
169 .owner
= THIS_MODULE
,
173 static int __init
parport_atari_init(void)
179 local_irq_save(flags
);
180 /* Soundchip port A/B as output. */
181 sound_ym
.rd_data_reg_sel
= 7;
182 sound_ym
.wd_data
= (sound_ym
.rd_data_reg_sel
& 0x3f) | 0xc0;
184 sound_ym
.rd_data_reg_sel
= 14;
185 sound_ym
.wd_data
= sound_ym
.rd_data_reg_sel
| (1 << 5);
186 local_irq_restore(flags
);
187 /* MFP port I0 as input. */
188 st_mfp
.data_dir
&= ~1;
189 /* MFP port I0 interrupt on high->low edge. */
190 st_mfp
.active_edge
&= ~1;
191 p
= parport_register_port((unsigned long)&sound_ym
.wd_data
,
192 IRQ_MFP_BUSY
, PARPORT_DMA_NONE
,
196 if (request_irq(IRQ_MFP_BUSY
, parport_irq_handler
, 0, p
->name
,
198 parport_put_port (p
);
203 pr_info("%s: Atari built-in port using irq\n", p
->name
);
204 parport_announce_port (p
);
211 static void __exit
parport_atari_exit(void)
213 parport_remove_port(this_port
);
214 if (this_port
->irq
!= PARPORT_IRQ_NONE
)
215 free_irq(IRQ_MFP_BUSY
, this_port
);
216 parport_put_port(this_port
);
219 MODULE_AUTHOR("Andreas Schwab");
220 MODULE_DESCRIPTION("Parport Driver for Atari builtin Port");
221 MODULE_SUPPORTED_DEVICE("Atari builtin Parallel Port");
222 MODULE_LICENSE("GPL");
224 module_init(parport_atari_init
)
225 module_exit(parport_atari_exit
)