parport_atari.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. #include <linux/module.h>
  12. #include <linux/init.h>
  13. #include <linux/parport.h>
  14. #include <linux/interrupt.h>
  15. #include <asm/setup.h>
  16. #include <asm/atarihw.h>
  17. #include <asm/irq.h>
  18. #include <asm/atariints.h>
  19. static struct parport *this_port = NULL;
  20. static unsigned char
  21. parport_atari_read_data(struct parport *p)
  22. {
  23. unsigned long flags;
  24. unsigned char data;
  25. local_irq_save(flags);
  26. sound_ym.rd_data_reg_sel = 15;
  27. data = sound_ym.rd_data_reg_sel;
  28. local_irq_restore(flags);
  29. return data;
  30. }
  31. static void
  32. parport_atari_write_data(struct parport *p, unsigned char data)
  33. {
  34. unsigned long flags;
  35. local_irq_save(flags);
  36. sound_ym.rd_data_reg_sel = 15;
  37. sound_ym.wd_data = data;
  38. local_irq_restore(flags);
  39. }
  40. static unsigned char
  41. parport_atari_read_control(struct parport *p)
  42. {
  43. unsigned long flags;
  44. unsigned char control = 0;
  45. local_irq_save(flags);
  46. sound_ym.rd_data_reg_sel = 14;
  47. if (!(sound_ym.rd_data_reg_sel & (1 << 5)))
  48. control = PARPORT_CONTROL_STROBE;
  49. local_irq_restore(flags);
  50. return control;
  51. }
  52. static void
  53. parport_atari_write_control(struct parport *p, unsigned char control)
  54. {
  55. unsigned long flags;
  56. local_irq_save(flags);
  57. sound_ym.rd_data_reg_sel = 14;
  58. if (control & PARPORT_CONTROL_STROBE)
  59. sound_ym.wd_data = sound_ym.rd_data_reg_sel & ~(1 << 5);
  60. else
  61. sound_ym.wd_data = sound_ym.rd_data_reg_sel | (1 << 5);
  62. local_irq_restore(flags);
  63. }
  64. static unsigned char
  65. parport_atari_frob_control(struct parport *p, unsigned char mask,
  66. unsigned char val)
  67. {
  68. unsigned char old = parport_atari_read_control(p);
  69. parport_atari_write_control(p, (old & ~mask) ^ val);
  70. return old;
  71. }
  72. static unsigned char
  73. parport_atari_read_status(struct parport *p)
  74. {
  75. return ((st_mfp.par_dt_reg & 1 ? 0 : PARPORT_STATUS_BUSY) |
  76. PARPORT_STATUS_SELECT | PARPORT_STATUS_ERROR);
  77. }
  78. static void
  79. parport_atari_init_state(struct pardevice *d, struct parport_state *s)
  80. {
  81. }
  82. static void
  83. parport_atari_save_state(struct parport *p, struct parport_state *s)
  84. {
  85. }
  86. static void
  87. parport_atari_restore_state(struct parport *p, struct parport_state *s)
  88. {
  89. }
  90. static void
  91. parport_atari_enable_irq(struct parport *p)
  92. {
  93. enable_irq(IRQ_MFP_BUSY);
  94. }
  95. static void
  96. parport_atari_disable_irq(struct parport *p)
  97. {
  98. disable_irq(IRQ_MFP_BUSY);
  99. }
  100. static void
  101. parport_atari_data_forward(struct parport *p)
  102. {
  103. unsigned long flags;
  104. local_irq_save(flags);
  105. /* Soundchip port B as output. */
  106. sound_ym.rd_data_reg_sel = 7;
  107. sound_ym.wd_data = sound_ym.rd_data_reg_sel | 0x40;
  108. local_irq_restore(flags);
  109. }
  110. static void
  111. parport_atari_data_reverse(struct parport *p)
  112. {
  113. }
  114. static struct parport_operations parport_atari_ops = {
  115. .write_data = parport_atari_write_data,
  116. .read_data = parport_atari_read_data,
  117. .write_control = parport_atari_write_control,
  118. .read_control = parport_atari_read_control,
  119. .frob_control = parport_atari_frob_control,
  120. .read_status = parport_atari_read_status,
  121. .enable_irq = parport_atari_enable_irq,
  122. .disable_irq = parport_atari_disable_irq,
  123. .data_forward = parport_atari_data_forward,
  124. .data_reverse = parport_atari_data_reverse,
  125. .init_state = parport_atari_init_state,
  126. .save_state = parport_atari_save_state,
  127. .restore_state = parport_atari_restore_state,
  128. .epp_write_data = parport_ieee1284_epp_write_data,
  129. .epp_read_data = parport_ieee1284_epp_read_data,
  130. .epp_write_addr = parport_ieee1284_epp_write_addr,
  131. .epp_read_addr = parport_ieee1284_epp_read_addr,
  132. .ecp_write_data = parport_ieee1284_ecp_write_data,
  133. .ecp_read_data = parport_ieee1284_ecp_read_data,
  134. .ecp_write_addr = parport_ieee1284_ecp_write_addr,
  135. .compat_write_data = parport_ieee1284_write_compat,
  136. .nibble_read_data = parport_ieee1284_read_nibble,
  137. .byte_read_data = parport_ieee1284_read_byte,
  138. .owner = THIS_MODULE,
  139. };
  140. static int __init parport_atari_init(void)
  141. {
  142. struct parport *p;
  143. unsigned long flags;
  144. if (MACH_IS_ATARI) {
  145. local_irq_save(flags);
  146. /* Soundchip port A/B as output. */
  147. sound_ym.rd_data_reg_sel = 7;
  148. sound_ym.wd_data = (sound_ym.rd_data_reg_sel & 0x3f) | 0xc0;
  149. /* STROBE high. */
  150. sound_ym.rd_data_reg_sel = 14;
  151. sound_ym.wd_data = sound_ym.rd_data_reg_sel | (1 << 5);
  152. local_irq_restore(flags);
  153. /* MFP port I0 as input. */
  154. st_mfp.data_dir &= ~1;
  155. /* MFP port I0 interrupt on high->low edge. */
  156. st_mfp.active_edge &= ~1;
  157. p = parport_register_port((unsigned long)&sound_ym.wd_data,
  158. IRQ_MFP_BUSY, PARPORT_DMA_NONE,
  159. &parport_atari_ops);
  160. if (!p)
  161. return -ENODEV;
  162. if (request_irq(IRQ_MFP_BUSY, parport_irq_handler, 0, p->name,
  163. p)) {
  164. parport_put_port (p);
  165. return -ENODEV;
  166. }
  167. this_port = p;
  168. printk(KERN_INFO "%s: Atari built-in port using irq\n", p->name);
  169. parport_announce_port (p);
  170. return 0;
  171. }
  172. return -ENODEV;
  173. }
  174. static void __exit parport_atari_exit(void)
  175. {
  176. parport_remove_port(this_port);
  177. if (this_port->irq != PARPORT_IRQ_NONE)
  178. free_irq(IRQ_MFP_BUSY, this_port);
  179. parport_put_port(this_port);
  180. }
  181. MODULE_AUTHOR("Andreas Schwab");
  182. MODULE_DESCRIPTION("Parport Driver for Atari builtin Port");
  183. MODULE_SUPPORTED_DEVICE("Atari builtin Parallel Port");
  184. MODULE_LICENSE("GPL");
  185. module_init(parport_atari_init)
  186. module_exit(parport_atari_exit)