briq_panel.c 5.3 KB

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