parport_amiga.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /* Low-level parallel port routines for the Amiga built-in port
  2. *
  3. * Author: Joerg Dorchain <joerg@dorchain.net>
  4. *
  5. * This is a complete rewrite of the code, but based heaviy upon the old
  6. * lp_intern. code.
  7. *
  8. * The built-in Amiga parallel port provides one port at a fixed address
  9. * with 8 bidirectional data lines (D0 - D7) and 3 bidirectional status
  10. * lines (BUSY, POUT, SEL), 1 output control line /STROBE (raised automatically
  11. * in hardware when the data register is accessed), and 1 input control line
  12. * /ACK, able to cause an interrupt, but both not directly settable by
  13. * software.
  14. */
  15. #include <linux/module.h>
  16. #include <linux/init.h>
  17. #include <linux/parport.h>
  18. #include <linux/ioport.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/platform_device.h>
  21. #include <asm/setup.h>
  22. #include <asm/amigahw.h>
  23. #include <asm/irq.h>
  24. #include <asm/io.h>
  25. #include <asm/amigaints.h>
  26. #undef DEBUG
  27. #ifdef DEBUG
  28. #define DPRINTK printk
  29. #else
  30. #define DPRINTK(x...) do { } while (0)
  31. #endif
  32. static void amiga_write_data(struct parport *p, unsigned char data)
  33. {
  34. DPRINTK(KERN_DEBUG "write_data %c\n",data);
  35. /* Triggers also /STROBE. This behavior cannot be changed */
  36. ciaa.prb = data;
  37. mb();
  38. }
  39. static unsigned char amiga_read_data(struct parport *p)
  40. {
  41. /* Triggers also /STROBE. This behavior cannot be changed */
  42. return ciaa.prb;
  43. }
  44. static unsigned char control_amiga_to_pc(unsigned char control)
  45. {
  46. return PARPORT_CONTROL_SELECT |
  47. PARPORT_CONTROL_AUTOFD | PARPORT_CONTROL_STROBE;
  48. /* fake value: interrupt enable, select in, no reset,
  49. no autolf, no strobe - seems to be closest the wiring diagram */
  50. }
  51. static void amiga_write_control(struct parport *p, unsigned char control)
  52. {
  53. DPRINTK(KERN_DEBUG "write_control %02x\n",control);
  54. /* No implementation possible */
  55. }
  56. static unsigned char amiga_read_control( struct parport *p)
  57. {
  58. DPRINTK(KERN_DEBUG "read_control \n");
  59. return control_amiga_to_pc(0);
  60. }
  61. static unsigned char amiga_frob_control( struct parport *p, unsigned char mask, unsigned char val)
  62. {
  63. unsigned char old;
  64. DPRINTK(KERN_DEBUG "frob_control mask %02x, value %02x\n",mask,val);
  65. old = amiga_read_control(p);
  66. amiga_write_control(p, (old & ~mask) ^ val);
  67. return old;
  68. }
  69. static unsigned char status_amiga_to_pc(unsigned char status)
  70. {
  71. unsigned char ret = PARPORT_STATUS_BUSY | PARPORT_STATUS_ACK | PARPORT_STATUS_ERROR;
  72. if (status & 1) /* Busy */
  73. ret &= ~PARPORT_STATUS_BUSY;
  74. if (status & 2) /* PaperOut */
  75. ret |= PARPORT_STATUS_PAPEROUT;
  76. if (status & 4) /* Selected */
  77. ret |= PARPORT_STATUS_SELECT;
  78. /* the rest is not connected or handled autonomously in hardware */
  79. return ret;
  80. }
  81. static unsigned char amiga_read_status(struct parport *p)
  82. {
  83. unsigned char status;
  84. status = status_amiga_to_pc(ciab.pra & 7);
  85. DPRINTK(KERN_DEBUG "read_status %02x\n", status);
  86. return status;
  87. }
  88. static void amiga_enable_irq(struct parport *p)
  89. {
  90. enable_irq(IRQ_AMIGA_CIAA_FLG);
  91. }
  92. static void amiga_disable_irq(struct parport *p)
  93. {
  94. disable_irq(IRQ_AMIGA_CIAA_FLG);
  95. }
  96. static void amiga_data_forward(struct parport *p)
  97. {
  98. DPRINTK(KERN_DEBUG "forward\n");
  99. ciaa.ddrb = 0xff; /* all pins output */
  100. mb();
  101. }
  102. static void amiga_data_reverse(struct parport *p)
  103. {
  104. DPRINTK(KERN_DEBUG "reverse\n");
  105. ciaa.ddrb = 0; /* all pins input */
  106. mb();
  107. }
  108. static void amiga_init_state(struct pardevice *dev, struct parport_state *s)
  109. {
  110. s->u.amiga.data = 0;
  111. s->u.amiga.datadir = 255;
  112. s->u.amiga.status = 0;
  113. s->u.amiga.statusdir = 0;
  114. }
  115. static void amiga_save_state(struct parport *p, struct parport_state *s)
  116. {
  117. mb();
  118. s->u.amiga.data = ciaa.prb;
  119. s->u.amiga.datadir = ciaa.ddrb;
  120. s->u.amiga.status = ciab.pra & 7;
  121. s->u.amiga.statusdir = ciab.ddra & 7;
  122. mb();
  123. }
  124. static void amiga_restore_state(struct parport *p, struct parport_state *s)
  125. {
  126. mb();
  127. ciaa.prb = s->u.amiga.data;
  128. ciaa.ddrb = s->u.amiga.datadir;
  129. ciab.pra |= (ciab.pra & 0xf8) | s->u.amiga.status;
  130. ciab.ddra |= (ciab.ddra & 0xf8) | s->u.amiga.statusdir;
  131. mb();
  132. }
  133. static struct parport_operations pp_amiga_ops = {
  134. .write_data = amiga_write_data,
  135. .read_data = amiga_read_data,
  136. .write_control = amiga_write_control,
  137. .read_control = amiga_read_control,
  138. .frob_control = amiga_frob_control,
  139. .read_status = amiga_read_status,
  140. .enable_irq = amiga_enable_irq,
  141. .disable_irq = amiga_disable_irq,
  142. .data_forward = amiga_data_forward,
  143. .data_reverse = amiga_data_reverse,
  144. .init_state = amiga_init_state,
  145. .save_state = amiga_save_state,
  146. .restore_state = amiga_restore_state,
  147. .epp_write_data = parport_ieee1284_epp_write_data,
  148. .epp_read_data = parport_ieee1284_epp_read_data,
  149. .epp_write_addr = parport_ieee1284_epp_write_addr,
  150. .epp_read_addr = parport_ieee1284_epp_read_addr,
  151. .ecp_write_data = parport_ieee1284_ecp_write_data,
  152. .ecp_read_data = parport_ieee1284_ecp_read_data,
  153. .ecp_write_addr = parport_ieee1284_ecp_write_addr,
  154. .compat_write_data = parport_ieee1284_write_compat,
  155. .nibble_read_data = parport_ieee1284_read_nibble,
  156. .byte_read_data = parport_ieee1284_read_byte,
  157. .owner = THIS_MODULE,
  158. };
  159. /* ----------- Initialisation code --------------------------------- */
  160. static int __init amiga_parallel_probe(struct platform_device *pdev)
  161. {
  162. struct parport *p;
  163. int err;
  164. ciaa.ddrb = 0xff;
  165. ciab.ddra &= 0xf8;
  166. mb();
  167. p = parport_register_port((unsigned long)&ciaa.prb, IRQ_AMIGA_CIAA_FLG,
  168. PARPORT_DMA_NONE, &pp_amiga_ops);
  169. if (!p)
  170. return -EBUSY;
  171. err = request_irq(IRQ_AMIGA_CIAA_FLG, parport_irq_handler, 0, p->name,
  172. p);
  173. if (err)
  174. goto out_irq;
  175. printk(KERN_INFO "%s: Amiga built-in port using irq\n", p->name);
  176. /* XXX: set operating mode */
  177. parport_announce_port(p);
  178. platform_set_drvdata(pdev, p);
  179. return 0;
  180. out_irq:
  181. parport_put_port(p);
  182. return err;
  183. }
  184. static int __exit amiga_parallel_remove(struct platform_device *pdev)
  185. {
  186. struct parport *port = platform_get_drvdata(pdev);
  187. parport_remove_port(port);
  188. if (port->irq != PARPORT_IRQ_NONE)
  189. free_irq(IRQ_AMIGA_CIAA_FLG, port);
  190. parport_put_port(port);
  191. return 0;
  192. }
  193. static struct platform_driver amiga_parallel_driver = {
  194. .remove = __exit_p(amiga_parallel_remove),
  195. .driver = {
  196. .name = "amiga-parallel",
  197. },
  198. };
  199. module_platform_driver_probe(amiga_parallel_driver, amiga_parallel_probe);
  200. MODULE_AUTHOR("Joerg Dorchain <joerg@dorchain.net>");
  201. MODULE_DESCRIPTION("Parport Driver for Amiga builtin Port");
  202. MODULE_SUPPORTED_DEVICE("Amiga builtin Parallel Port");
  203. MODULE_LICENSE("GPL");
  204. MODULE_ALIAS("platform:amiga-parallel");