parport_amiga.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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. #if 0
  45. static unsigned char control_pc_to_amiga(unsigned char control)
  46. {
  47. unsigned char ret = 0;
  48. if (control & PARPORT_CONTROL_SELECT) /* XXX: What is SELECP? */
  49. ;
  50. if (control & PARPORT_CONTROL_INIT) /* INITP */
  51. /* reset connected to cpu reset pin */;
  52. if (control & PARPORT_CONTROL_AUTOFD) /* AUTOLF */
  53. /* Not connected */;
  54. if (control & PARPORT_CONTROL_STROBE) /* Strobe */
  55. /* Handled only directly by hardware */;
  56. return ret;
  57. }
  58. #endif
  59. static unsigned char control_amiga_to_pc(unsigned char control)
  60. {
  61. return PARPORT_CONTROL_SELECT |
  62. PARPORT_CONTROL_AUTOFD | PARPORT_CONTROL_STROBE;
  63. /* fake value: interrupt enable, select in, no reset,
  64. no autolf, no strobe - seems to be closest the wiring diagram */
  65. }
  66. static void amiga_write_control(struct parport *p, unsigned char control)
  67. {
  68. DPRINTK(KERN_DEBUG "write_control %02x\n",control);
  69. /* No implementation possible */
  70. }
  71. static unsigned char amiga_read_control( struct parport *p)
  72. {
  73. DPRINTK(KERN_DEBUG "read_control \n");
  74. return control_amiga_to_pc(0);
  75. }
  76. static unsigned char amiga_frob_control( struct parport *p, unsigned char mask, unsigned char val)
  77. {
  78. unsigned char old;
  79. DPRINTK(KERN_DEBUG "frob_control mask %02x, value %02x\n",mask,val);
  80. old = amiga_read_control(p);
  81. amiga_write_control(p, (old & ~mask) ^ val);
  82. return old;
  83. }
  84. #if 0 /* currently unused */
  85. static unsigned char status_pc_to_amiga(unsigned char status)
  86. {
  87. unsigned char ret = 1;
  88. if (status & PARPORT_STATUS_BUSY) /* Busy */
  89. ret &= ~1;
  90. if (status & PARPORT_STATUS_ACK) /* Ack */
  91. /* handled in hardware */;
  92. if (status & PARPORT_STATUS_PAPEROUT) /* PaperOut */
  93. ret |= 2;
  94. if (status & PARPORT_STATUS_SELECT) /* select */
  95. ret |= 4;
  96. if (status & PARPORT_STATUS_ERROR) /* error */
  97. /* not connected */;
  98. return ret;
  99. }
  100. #endif
  101. static unsigned char status_amiga_to_pc(unsigned char status)
  102. {
  103. unsigned char ret = PARPORT_STATUS_BUSY | PARPORT_STATUS_ACK | PARPORT_STATUS_ERROR;
  104. if (status & 1) /* Busy */
  105. ret &= ~PARPORT_STATUS_BUSY;
  106. if (status & 2) /* PaperOut */
  107. ret |= PARPORT_STATUS_PAPEROUT;
  108. if (status & 4) /* Selected */
  109. ret |= PARPORT_STATUS_SELECT;
  110. /* the rest is not connected or handled autonomously in hardware */
  111. return ret;
  112. }
  113. static unsigned char amiga_read_status(struct parport *p)
  114. {
  115. unsigned char status;
  116. status = status_amiga_to_pc(ciab.pra & 7);
  117. DPRINTK(KERN_DEBUG "read_status %02x\n", status);
  118. return status;
  119. }
  120. static void amiga_enable_irq(struct parport *p)
  121. {
  122. enable_irq(IRQ_AMIGA_CIAA_FLG);
  123. }
  124. static void amiga_disable_irq(struct parport *p)
  125. {
  126. disable_irq(IRQ_AMIGA_CIAA_FLG);
  127. }
  128. static void amiga_data_forward(struct parport *p)
  129. {
  130. DPRINTK(KERN_DEBUG "forward\n");
  131. ciaa.ddrb = 0xff; /* all pins output */
  132. mb();
  133. }
  134. static void amiga_data_reverse(struct parport *p)
  135. {
  136. DPRINTK(KERN_DEBUG "reverse\n");
  137. ciaa.ddrb = 0; /* all pins input */
  138. mb();
  139. }
  140. static void amiga_init_state(struct pardevice *dev, struct parport_state *s)
  141. {
  142. s->u.amiga.data = 0;
  143. s->u.amiga.datadir = 255;
  144. s->u.amiga.status = 0;
  145. s->u.amiga.statusdir = 0;
  146. }
  147. static void amiga_save_state(struct parport *p, struct parport_state *s)
  148. {
  149. mb();
  150. s->u.amiga.data = ciaa.prb;
  151. s->u.amiga.datadir = ciaa.ddrb;
  152. s->u.amiga.status = ciab.pra & 7;
  153. s->u.amiga.statusdir = ciab.ddra & 7;
  154. mb();
  155. }
  156. static void amiga_restore_state(struct parport *p, struct parport_state *s)
  157. {
  158. mb();
  159. ciaa.prb = s->u.amiga.data;
  160. ciaa.ddrb = s->u.amiga.datadir;
  161. ciab.pra |= (ciab.pra & 0xf8) | s->u.amiga.status;
  162. ciab.ddra |= (ciab.ddra & 0xf8) | s->u.amiga.statusdir;
  163. mb();
  164. }
  165. static struct parport_operations pp_amiga_ops = {
  166. .write_data = amiga_write_data,
  167. .read_data = amiga_read_data,
  168. .write_control = amiga_write_control,
  169. .read_control = amiga_read_control,
  170. .frob_control = amiga_frob_control,
  171. .read_status = amiga_read_status,
  172. .enable_irq = amiga_enable_irq,
  173. .disable_irq = amiga_disable_irq,
  174. .data_forward = amiga_data_forward,
  175. .data_reverse = amiga_data_reverse,
  176. .init_state = amiga_init_state,
  177. .save_state = amiga_save_state,
  178. .restore_state = amiga_restore_state,
  179. .epp_write_data = parport_ieee1284_epp_write_data,
  180. .epp_read_data = parport_ieee1284_epp_read_data,
  181. .epp_write_addr = parport_ieee1284_epp_write_addr,
  182. .epp_read_addr = parport_ieee1284_epp_read_addr,
  183. .ecp_write_data = parport_ieee1284_ecp_write_data,
  184. .ecp_read_data = parport_ieee1284_ecp_read_data,
  185. .ecp_write_addr = parport_ieee1284_ecp_write_addr,
  186. .compat_write_data = parport_ieee1284_write_compat,
  187. .nibble_read_data = parport_ieee1284_read_nibble,
  188. .byte_read_data = parport_ieee1284_read_byte,
  189. .owner = THIS_MODULE,
  190. };
  191. /* ----------- Initialisation code --------------------------------- */
  192. static int __init amiga_parallel_probe(struct platform_device *pdev)
  193. {
  194. struct parport *p;
  195. int err;
  196. ciaa.ddrb = 0xff;
  197. ciab.ddra &= 0xf8;
  198. mb();
  199. p = parport_register_port((unsigned long)&ciaa.prb, IRQ_AMIGA_CIAA_FLG,
  200. PARPORT_DMA_NONE, &pp_amiga_ops);
  201. if (!p)
  202. return -EBUSY;
  203. err = request_irq(IRQ_AMIGA_CIAA_FLG, parport_irq_handler, 0, p->name,
  204. p);
  205. if (err)
  206. goto out_irq;
  207. printk(KERN_INFO "%s: Amiga built-in port using irq\n", p->name);
  208. /* XXX: set operating mode */
  209. parport_announce_port(p);
  210. platform_set_drvdata(pdev, p);
  211. return 0;
  212. out_irq:
  213. parport_put_port(p);
  214. return err;
  215. }
  216. static int __exit amiga_parallel_remove(struct platform_device *pdev)
  217. {
  218. struct parport *port = platform_get_drvdata(pdev);
  219. parport_remove_port(port);
  220. if (port->irq != PARPORT_IRQ_NONE)
  221. free_irq(IRQ_AMIGA_CIAA_FLG, port);
  222. parport_put_port(port);
  223. platform_set_drvdata(pdev, NULL);
  224. return 0;
  225. }
  226. static struct platform_driver amiga_parallel_driver = {
  227. .remove = __exit_p(amiga_parallel_remove),
  228. .driver = {
  229. .name = "amiga-parallel",
  230. .owner = THIS_MODULE,
  231. },
  232. };
  233. static int __init amiga_parallel_init(void)
  234. {
  235. return platform_driver_probe(&amiga_parallel_driver,
  236. amiga_parallel_probe);
  237. }
  238. module_init(amiga_parallel_init);
  239. static void __exit amiga_parallel_exit(void)
  240. {
  241. platform_driver_unregister(&amiga_parallel_driver);
  242. }
  243. module_exit(amiga_parallel_exit);
  244. MODULE_AUTHOR("Joerg Dorchain <joerg@dorchain.net>");
  245. MODULE_DESCRIPTION("Parport Driver for Amiga builtin Port");
  246. MODULE_SUPPORTED_DEVICE("Amiga builtin Parallel Port");
  247. MODULE_LICENSE("GPL");
  248. MODULE_ALIAS("platform:amiga-parallel");