parport_atari.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. #if 0 /* too dangerous, can kill sound chip */
  114. unsigned long flags;
  115. local_irq_save(flags);
  116. /* Soundchip port B as input. */
  117. sound_ym.rd_data_reg_sel = 7;
  118. sound_ym.wd_data = sound_ym.rd_data_reg_sel & ~0x40;
  119. local_irq_restore(flags);
  120. #endif
  121. }
  122. static struct parport_operations parport_atari_ops = {
  123. .write_data = parport_atari_write_data,
  124. .read_data = parport_atari_read_data,
  125. .write_control = parport_atari_write_control,
  126. .read_control = parport_atari_read_control,
  127. .frob_control = parport_atari_frob_control,
  128. .read_status = parport_atari_read_status,
  129. .enable_irq = parport_atari_enable_irq,
  130. .disable_irq = parport_atari_disable_irq,
  131. .data_forward = parport_atari_data_forward,
  132. .data_reverse = parport_atari_data_reverse,
  133. .init_state = parport_atari_init_state,
  134. .save_state = parport_atari_save_state,
  135. .restore_state = parport_atari_restore_state,
  136. .epp_write_data = parport_ieee1284_epp_write_data,
  137. .epp_read_data = parport_ieee1284_epp_read_data,
  138. .epp_write_addr = parport_ieee1284_epp_write_addr,
  139. .epp_read_addr = parport_ieee1284_epp_read_addr,
  140. .ecp_write_data = parport_ieee1284_ecp_write_data,
  141. .ecp_read_data = parport_ieee1284_ecp_read_data,
  142. .ecp_write_addr = parport_ieee1284_ecp_write_addr,
  143. .compat_write_data = parport_ieee1284_write_compat,
  144. .nibble_read_data = parport_ieee1284_read_nibble,
  145. .byte_read_data = parport_ieee1284_read_byte,
  146. .owner = THIS_MODULE,
  147. };
  148. static int __init parport_atari_init(void)
  149. {
  150. struct parport *p;
  151. unsigned long flags;
  152. if (MACH_IS_ATARI) {
  153. local_irq_save(flags);
  154. /* Soundchip port A/B as output. */
  155. sound_ym.rd_data_reg_sel = 7;
  156. sound_ym.wd_data = (sound_ym.rd_data_reg_sel & 0x3f) | 0xc0;
  157. /* STROBE high. */
  158. sound_ym.rd_data_reg_sel = 14;
  159. sound_ym.wd_data = sound_ym.rd_data_reg_sel | (1 << 5);
  160. local_irq_restore(flags);
  161. /* MFP port I0 as input. */
  162. st_mfp.data_dir &= ~1;
  163. /* MFP port I0 interrupt on high->low edge. */
  164. st_mfp.active_edge &= ~1;
  165. p = parport_register_port((unsigned long)&sound_ym.wd_data,
  166. IRQ_MFP_BUSY, PARPORT_DMA_NONE,
  167. &parport_atari_ops);
  168. if (!p)
  169. return -ENODEV;
  170. if (request_irq(IRQ_MFP_BUSY, parport_irq_handler,
  171. IRQ_TYPE_SLOW, p->name, p)) {
  172. parport_put_port (p);
  173. return -ENODEV;
  174. }
  175. this_port = p;
  176. printk(KERN_INFO "%s: Atari built-in port using irq\n", p->name);
  177. parport_announce_port (p);
  178. return 0;
  179. }
  180. return -ENODEV;
  181. }
  182. static void __exit parport_atari_exit(void)
  183. {
  184. parport_remove_port(this_port);
  185. if (this_port->irq != PARPORT_IRQ_NONE)
  186. free_irq(IRQ_MFP_BUSY, this_port);
  187. parport_put_port(this_port);
  188. }
  189. MODULE_AUTHOR("Andreas Schwab");
  190. MODULE_DESCRIPTION("Parport Driver for Atari builtin Port");
  191. MODULE_SUPPORTED_DEVICE("Atari builtin Parallel Port");
  192. MODULE_LICENSE("GPL");
  193. module_init(parport_atari_init)
  194. module_exit(parport_atari_exit)