1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
|
/* Low-level parallel port routines for the Atari builtin port
*
* Author: Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
*
* Based on parport_amiga.c.
*
* The built-in Atari parallel port provides one port at a fixed address
* with 8 output data lines (D0 - D7), 1 output control line (STROBE)
* and 1 input status line (BUSY) able to cause an interrupt.
*/
#include <linux/module.h>
#include <linux/init.h>
#include <linux/parport.h>
#include <asm/setup.h>
#include <asm/atarihw.h>
#include <asm/irq.h>
#include <asm/atariints.h>
static struct parport *this_port = NULL;
static unsigned char
parport_atari_read_data(struct parport *p)
{
unsigned long flags;
unsigned char data;
save_flags(flags);
cli();
sound_ym.rd_data_reg_sel = 15;
data = sound_ym.rd_data_reg_sel;
restore_flags(flags);
return data;
}
static void
parport_atari_write_data(struct parport *p, unsigned char data)
{
unsigned long flags;
save_flags(flags);
cli();
sound_ym.rd_data_reg_sel = 15;
sound_ym.wd_data = data;
restore_flags(flags);
}
static unsigned char
parport_atari_read_control(struct parport *p)
{
unsigned long flags;
unsigned char control = 0;
save_flags(flags);
cli();
sound_ym.rd_data_reg_sel = 14;
if (!(sound_ym.rd_data_reg_sel & (1 << 5)))
control = PARPORT_CONTROL_STROBE;
restore_flags(flags);
return control;
}
static void
parport_atari_write_control(struct parport *p, unsigned char control)
{
unsigned long flags;
save_flags(flags);
cli();
sound_ym.rd_data_reg_sel = 14;
if (control & PARPORT_CONTROL_STROBE)
sound_ym.wd_data = sound_ym.rd_data_reg_sel & ~(1 << 5);
else
sound_ym.wd_data = sound_ym.rd_data_reg_sel | (1 << 5);
restore_flags(flags);
}
static unsigned char
parport_atari_frob_control(struct parport *p, unsigned char mask,
unsigned char val)
{
unsigned char old = parport_atari_read_control(p);
parport_atari_write_control(p, (old & ~mask) ^ val);
return old;
}
static unsigned char
parport_atari_read_status(struct parport *p)
{
return ((mfp.par_dt_reg & 1 ? 0 : PARPORT_STATUS_BUSY) |
PARPORT_STATUS_SELECT | PARPORT_STATUS_ERROR);
}
static void
parport_atari_init_state(struct pardevice *d, struct parport_state *s)
{
}
static void
parport_atari_save_state(struct parport *p, struct parport_state *s)
{
}
static void
parport_atari_restore_state(struct parport *p, struct parport_state *s)
{
}
static void
parport_atari_interrupt(int irq, void *dev_id, struct pt_regs *regs)
{
parport_generic_irq(irq, (struct parport *) dev_id, regs);
}
static void
parport_atari_inc_use_count(void)
{
MOD_INC_USE_COUNT;
}
static void
parport_atari_dec_use_count(void)
{
MOD_DEC_USE_COUNT;
}
static struct parport_operations parport_atari_ops = {
parport_atari_write_data,
parport_atari_read_data,
parport_atari_write_control,
parport_atari_read_control,
parport_atari_frob_control,
parport_atari_read_status,
NULL, /* enable_irq - FIXME */
NULL, /* disable_irq - FIXME */
NULL, /* data_forward - FIXME */
NULL, /* data_reverse - FIXME */
parport_atari_init_state,
parport_atari_save_state,
parport_atari_restore_state,
parport_atari_inc_use_count,
parport_atari_dec_use_count,
NULL, /* epp_write_data */
NULL, /* epp_read_data */
NULL, /* epp_write_addr */
NULL, /* epp_read_addr */
NULL, /* ecp_write_data */
NULL, /* ecp_read_data */
NULL, /* ecp_write_addr */
NULL, /* compat_write_data */
NULL, /* nibble_read_data */
NULL, /* byte_read_data */
};
int __init
parport_atari_init(void)
{
struct parport *p;
unsigned long flags;
if (MACH_IS_ATARI) {
save_flags(flags);
cli();
/* Soundchip port A/B as output. */
sound_ym.rd_data_reg_sel = 7;
sound_ym.wd_data = (sound_ym.rd_data_reg_sel & 0x3f) | 0xc0;
/* STROBE high. */
sound_ym.rd_data_reg_sel = 14;
sound_ym.wd_data = sound_ym.rd_data_reg_sel | (1 << 5);
restore_flags(flags);
/* MFP port I0 as input. */
mfp.data_dir &= ~1;
/* MFP port I0 interrupt on high->low edge. */
mfp.active_edge &= ~1;
p = parport_register_port((unsigned long)&sound_ym.wd_data,
IRQ_MFP_BUSY, PARPORT_DMA_NONE,
&parport_atari_ops);
if (!p)
return 0;
if (request_irq(IRQ_MFP_BUSY, parport_atari_interrupt,
IRQ_TYPE_SLOW, p->name, p)) {
parport_unregister_port (p);
return 0;
}
this_port = p;
printk(KERN_INFO "%s: Atari built-in port using irq\n", p->name);
parport_proc_register(p);
parport_announce_port (p);
return 1;
}
return 0;
}
#ifdef MODULE
MODULE_AUTHOR("Andreas Schwab");
MODULE_DESCRIPTION("Parport Driver for Atari builtin Port");
MODULE_SUPPORTED_DEVICE("Atari builtin Parallel Port");
int
init_module(void)
{
return parport_atari_init() ? 0 : -ENODEV;
}
void
cleanup_module(void)
{
if (this_port->irq != PARPORT_IRQ_NONE)
free_irq(IRQ_MFP_BUSY, this_port);
parport_proc_unregister(this_port);
parport_unregister_port(this_port);
}
#endif
|