briq_panel.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /*
  2. * Drivers for the Total Impact PPC based computer "BRIQ"
  3. * by Dr. Karsten Jeppesen
  4. *
  5. */
  6. #include <linux/module.h>
  7. #include <linux/types.h>
  8. #include <linux/errno.h>
  9. #include <linux/tty.h>
  10. #include <linux/timer.h>
  11. #include <linux/kernel.h>
  12. #include <linux/wait.h>
  13. #include <linux/string.h>
  14. #include <linux/slab.h>
  15. #include <linux/ioport.h>
  16. #include <linux/delay.h>
  17. #include <linux/miscdevice.h>
  18. #include <linux/fs.h>
  19. #include <linux/mm.h>
  20. #include <linux/init.h>
  21. #include <asm/uaccess.h>
  22. #include <asm/io.h>
  23. #include <asm/prom.h>
  24. #define BRIQ_PANEL_MINOR 156
  25. #define BRIQ_PANEL_VFD_IOPORT 0x0390
  26. #define BRIQ_PANEL_LED_IOPORT 0x0398
  27. #define BRIQ_PANEL_VER "1.1 (04/20/2002)"
  28. #define BRIQ_PANEL_MSG0 "Loading Linux"
  29. static int vfd_is_open;
  30. static unsigned char vfd[40];
  31. static int vfd_cursor;
  32. static unsigned char ledpb, led;
  33. static void update_vfd(void)
  34. {
  35. int i;
  36. /* cursor home */
  37. outb(0x02, BRIQ_PANEL_VFD_IOPORT);
  38. for (i=0; i<20; i++)
  39. outb(vfd[i], BRIQ_PANEL_VFD_IOPORT + 1);
  40. /* cursor to next line */
  41. outb(0xc0, BRIQ_PANEL_VFD_IOPORT);
  42. for (i=20; i<40; i++)
  43. outb(vfd[i], BRIQ_PANEL_VFD_IOPORT + 1);
  44. }
  45. static void set_led(char state)
  46. {
  47. if (state == 'R')
  48. led = 0x01;
  49. else if (state == 'G')
  50. led = 0x02;
  51. else if (state == 'Y')
  52. led = 0x03;
  53. else if (state == 'X')
  54. led = 0x00;
  55. outb(led, BRIQ_PANEL_LED_IOPORT);
  56. }
  57. static int briq_panel_open(struct inode *ino, struct file *filep)
  58. {
  59. /* enforce single access */
  60. if (vfd_is_open)
  61. return -EBUSY;
  62. vfd_is_open = 1;
  63. return 0;
  64. }
  65. static int briq_panel_release(struct inode *ino, struct file *filep)
  66. {
  67. if (!vfd_is_open)
  68. return -ENODEV;
  69. vfd_is_open = 0;
  70. return 0;
  71. }
  72. static ssize_t briq_panel_read(struct file *file, char __user *buf, size_t count,
  73. loff_t *ppos)
  74. {
  75. unsigned short c;
  76. unsigned char cp;
  77. if (!vfd_is_open)
  78. return -ENODEV;
  79. c = (inb(BRIQ_PANEL_LED_IOPORT) & 0x000c) | (ledpb & 0x0003);
  80. set_led(' ');
  81. /* upper button released */
  82. if ((!(ledpb & 0x0004)) && (c & 0x0004)) {
  83. cp = ' ';
  84. ledpb = c;
  85. if (copy_to_user(buf, &cp, 1))
  86. return -EFAULT;
  87. return 1;
  88. }
  89. /* lower button released */
  90. else if ((!(ledpb & 0x0008)) && (c & 0x0008)) {
  91. cp = '\r';
  92. ledpb = c;
  93. if (copy_to_user(buf, &cp, 1))
  94. return -EFAULT;
  95. return 1;
  96. } else {
  97. ledpb = c;
  98. return 0;
  99. }
  100. }
  101. static void scroll_vfd( void )
  102. {
  103. int i;
  104. for (i=0; i<20; i++) {
  105. vfd[i] = vfd[i+20];
  106. vfd[i+20] = ' ';
  107. }
  108. vfd_cursor = 20;
  109. }
  110. static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_t len,
  111. loff_t *ppos)
  112. {
  113. size_t indx = len;
  114. int i, esc = 0;
  115. if (!vfd_is_open)
  116. return -EBUSY;
  117. for (;;) {
  118. char c;
  119. if (!indx)
  120. break;
  121. if (get_user(c, buf))
  122. return -EFAULT;
  123. if (esc) {
  124. set_led(c);
  125. esc = 0;
  126. } else if (c == 27) {
  127. esc = 1;
  128. } else if (c == 12) {
  129. /* do a form feed */
  130. for (i=0; i<40; i++)
  131. vfd[i] = ' ';
  132. vfd_cursor = 0;
  133. } else if (c == 10) {
  134. if (vfd_cursor < 20)
  135. vfd_cursor = 20;
  136. else if (vfd_cursor < 40)
  137. vfd_cursor = 40;
  138. else if (vfd_cursor < 60)
  139. vfd_cursor = 60;
  140. if (vfd_cursor > 59)
  141. scroll_vfd();
  142. } else {
  143. /* just a character */
  144. if (vfd_cursor > 39)
  145. scroll_vfd();
  146. vfd[vfd_cursor++] = c;
  147. }
  148. indx--;
  149. buf++;
  150. }
  151. update_vfd();
  152. return len;
  153. }
  154. static const struct file_operations briq_panel_fops = {
  155. .owner = THIS_MODULE,
  156. .read = briq_panel_read,
  157. .write = briq_panel_write,
  158. .open = briq_panel_open,
  159. .release = briq_panel_release,
  160. };
  161. static struct miscdevice briq_panel_miscdev = {
  162. BRIQ_PANEL_MINOR,
  163. "briq_panel",
  164. &briq_panel_fops
  165. };
  166. static int __init briq_panel_init(void)
  167. {
  168. struct device_node *root = of_find_node_by_path("/");
  169. const char *machine;
  170. int i;
  171. machine = of_get_property(root, "model", NULL);
  172. if (!machine || strncmp(machine, "TotalImpact,BRIQ-1", 18) != 0) {
  173. of_node_put(root);
  174. return -ENODEV;
  175. }
  176. of_node_put(root);
  177. printk(KERN_INFO
  178. "briq_panel: v%s Dr. Karsten Jeppesen (kj@totalimpact.com)\n",
  179. BRIQ_PANEL_VER);
  180. if (!request_region(BRIQ_PANEL_VFD_IOPORT, 4, "BRIQ Front Panel"))
  181. return -EBUSY;
  182. if (!request_region(BRIQ_PANEL_LED_IOPORT, 2, "BRIQ Front Panel")) {
  183. release_region(BRIQ_PANEL_VFD_IOPORT, 4);
  184. return -EBUSY;
  185. }
  186. ledpb = inb(BRIQ_PANEL_LED_IOPORT) & 0x000c;
  187. if (misc_register(&briq_panel_miscdev) < 0) {
  188. release_region(BRIQ_PANEL_VFD_IOPORT, 4);
  189. release_region(BRIQ_PANEL_LED_IOPORT, 2);
  190. return -EBUSY;
  191. }
  192. outb(0x38, BRIQ_PANEL_VFD_IOPORT); /* Function set */
  193. outb(0x01, BRIQ_PANEL_VFD_IOPORT); /* Clear display */
  194. outb(0x0c, BRIQ_PANEL_VFD_IOPORT); /* Display on */
  195. outb(0x06, BRIQ_PANEL_VFD_IOPORT); /* Entry normal */
  196. for (i=0; i<40; i++)
  197. vfd[i]=' ';
  198. #ifndef MODULE
  199. vfd[0] = 'L';
  200. vfd[1] = 'o';
  201. vfd[2] = 'a';
  202. vfd[3] = 'd';
  203. vfd[4] = 'i';
  204. vfd[5] = 'n';
  205. vfd[6] = 'g';
  206. vfd[7] = ' ';
  207. vfd[8] = '.';
  208. vfd[9] = '.';
  209. vfd[10] = '.';
  210. #endif /* !MODULE */
  211. update_vfd();
  212. return 0;
  213. }
  214. static void __exit briq_panel_exit(void)
  215. {
  216. misc_deregister(&briq_panel_miscdev);
  217. release_region(BRIQ_PANEL_VFD_IOPORT, 4);
  218. release_region(BRIQ_PANEL_LED_IOPORT, 2);
  219. }
  220. module_init(briq_panel_init);
  221. module_exit(briq_panel_exit);
  222. MODULE_LICENSE("GPL");
  223. MODULE_AUTHOR("Karsten Jeppesen <karsten@jeppesens.com>");
  224. MODULE_DESCRIPTION("Driver for the Total Impact briQ front panel");