Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* Low-level parallel port routines for the Atari builtin port |
| 2 | * |
| 3 | * Author: Andreas Schwab <schwab@issan.informatik.uni-dortmund.de> |
| 4 | * |
| 5 | * Based on parport_amiga.c. |
| 6 | * |
| 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. |
| 10 | */ |
| 11 | |
| 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> |
| 20 | |
| 21 | static struct parport *this_port = NULL; |
| 22 | |
| 23 | static unsigned char |
| 24 | parport_atari_read_data(struct parport *p) |
| 25 | { |
| 26 | unsigned long flags; |
| 27 | unsigned char data; |
| 28 | |
| 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; |
| 34 | } |
| 35 | |
| 36 | static void |
| 37 | parport_atari_write_data(struct parport *p, unsigned char data) |
| 38 | { |
| 39 | unsigned long flags; |
| 40 | |
| 41 | local_irq_save(flags); |
| 42 | sound_ym.rd_data_reg_sel = 15; |
| 43 | sound_ym.wd_data = data; |
| 44 | local_irq_restore(flags); |
| 45 | } |
| 46 | |
| 47 | static unsigned char |
| 48 | parport_atari_read_control(struct parport *p) |
| 49 | { |
| 50 | unsigned long flags; |
| 51 | unsigned char control = 0; |
| 52 | |
| 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; |
| 59 | } |
| 60 | |
| 61 | static void |
| 62 | parport_atari_write_control(struct parport *p, unsigned char control) |
| 63 | { |
| 64 | unsigned long flags; |
| 65 | |
| 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); |
| 73 | } |
| 74 | |
| 75 | static unsigned char |
| 76 | parport_atari_frob_control(struct parport *p, unsigned char mask, |
| 77 | unsigned char val) |
| 78 | { |
| 79 | unsigned char old = parport_atari_read_control(p); |
| 80 | parport_atari_write_control(p, (old & ~mask) ^ val); |
| 81 | return old; |
| 82 | } |
| 83 | |
| 84 | static unsigned char |
| 85 | parport_atari_read_status(struct parport *p) |
| 86 | { |
| 87 | return ((mfp.par_dt_reg & 1 ? 0 : PARPORT_STATUS_BUSY) | |
| 88 | PARPORT_STATUS_SELECT | PARPORT_STATUS_ERROR); |
| 89 | } |
| 90 | |
| 91 | static void |
| 92 | parport_atari_init_state(struct pardevice *d, struct parport_state *s) |
| 93 | { |
| 94 | } |
| 95 | |
| 96 | static void |
| 97 | parport_atari_save_state(struct parport *p, struct parport_state *s) |
| 98 | { |
| 99 | } |
| 100 | |
| 101 | static void |
| 102 | parport_atari_restore_state(struct parport *p, struct parport_state *s) |
| 103 | { |
| 104 | } |
| 105 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | static void |
| 107 | parport_atari_enable_irq(struct parport *p) |
| 108 | { |
| 109 | enable_irq(IRQ_MFP_BUSY); |
| 110 | } |
| 111 | |
| 112 | static void |
| 113 | parport_atari_disable_irq(struct parport *p) |
| 114 | { |
| 115 | disable_irq(IRQ_MFP_BUSY); |
| 116 | } |
| 117 | |
| 118 | static void |
| 119 | parport_atari_data_forward(struct parport *p) |
| 120 | { |
| 121 | unsigned long flags; |
| 122 | |
| 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); |
| 128 | } |
| 129 | |
| 130 | static void |
| 131 | parport_atari_data_reverse(struct parport *p) |
| 132 | { |
| 133 | #if 0 /* too dangerous, can kill sound chip */ |
| 134 | unsigned long flags; |
| 135 | |
| 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 |
| 142 | } |
| 143 | |
| 144 | static struct parport_operations parport_atari_ops = { |
| 145 | .write_data = parport_atari_write_data, |
| 146 | .read_data = parport_atari_read_data, |
| 147 | |
| 148 | .write_control = parport_atari_write_control, |
| 149 | .read_control = parport_atari_read_control, |
| 150 | .frob_control = parport_atari_frob_control, |
| 151 | |
| 152 | .read_status = parport_atari_read_status, |
| 153 | |
| 154 | .enable_irq = parport_atari_enable_irq, |
| 155 | .disable_irq = parport_atari_disable_irq, |
| 156 | |
| 157 | .data_forward = parport_atari_data_forward, |
| 158 | .data_reverse = parport_atari_data_reverse, |
| 159 | |
| 160 | .init_state = parport_atari_init_state, |
| 161 | .save_state = parport_atari_save_state, |
| 162 | .restore_state = parport_atari_restore_state, |
| 163 | |
| 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, |
| 168 | |
| 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, |
| 172 | |
| 173 | .compat_write_data = parport_ieee1284_write_compat, |
| 174 | .nibble_read_data = parport_ieee1284_read_nibble, |
| 175 | .byte_read_data = parport_ieee1284_read_byte, |
| 176 | |
| 177 | .owner = THIS_MODULE, |
| 178 | }; |
| 179 | |
| 180 | |
| 181 | static int __init parport_atari_init(void) |
| 182 | { |
| 183 | struct parport *p; |
| 184 | unsigned long flags; |
| 185 | |
| 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 | mfp.data_dir &= ~1; |
| 197 | /* MFP port I0 interrupt on high->low edge. */ |
| 198 | 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; |
Jeff Garzik | 3f2e40d | 2007-10-19 01:42:14 -0400 | [diff] [blame] | 204 | if (request_irq(IRQ_MFP_BUSY, parport_irq_handler, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | IRQ_TYPE_SLOW, p->name, p)) { |
| 206 | parport_put_port (p); |
| 207 | return -ENODEV; |
| 208 | } |
| 209 | |
| 210 | this_port = p; |
| 211 | printk(KERN_INFO "%s: Atari built-in port using irq\n", p->name); |
| 212 | parport_announce_port (p); |
| 213 | |
| 214 | return 0; |
| 215 | } |
| 216 | return -ENODEV; |
| 217 | } |
| 218 | |
| 219 | static void __exit parport_atari_exit(void) |
| 220 | { |
| 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); |
| 225 | } |
| 226 | |
| 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"); |
| 231 | |
| 232 | module_init(parport_atari_init) |
| 233 | module_exit(parport_atari_exit) |