briq_panel.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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 0 /* Can't seek (pread) on this device */
  78. if (ppos != &file->f_pos)
  79. return -ESPIPE;
  80. #endif
  81. if (!vfd_is_open)
  82. return -ENODEV;
  83. c = (inb(BRIQ_PANEL_LED_IOPORT) & 0x000c) | (ledpb & 0x0003);
  84. set_led(' ');
  85. /* upper button released */
  86. if ((!(ledpb & 0x0004)) && (c & 0x0004)) {
  87. cp = ' ';
  88. ledpb = c;
  89. if (copy_to_user(buf, &cp, 1))
  90. return -EFAULT;
  91. return 1;
  92. }
  93. /* lower button released */
  94. else if ((!(ledpb & 0x0008)) && (c & 0x0008)) {
  95. cp = '\r';
  96. ledpb = c;
  97. if (copy_to_user(buf, &cp, 1))
  98. return -EFAULT;
  99. return 1;
  100. } else {
  101. ledpb = c;
  102. return 0;
  103. }
  104. }
  105. static void scroll_vfd( void )
  106. {
  107. int i;
  108. for (i=0; i<20; i++) {
  109. vfd[i] = vfd[i+20];
  110. vfd[i+20] = ' ';
  111. }
  112. vfd_cursor = 20;
  113. }
  114. static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_t len,
  115. loff_t *ppos)
  116. {
  117. size_t indx = len;
  118. int i, esc = 0;
  119. #if 0 /* Can't seek (pwrite) on this device */
  120. if (ppos != &file->f_pos)
  121. return -ESPIPE;
  122. #endif
  123. if (!vfd_is_open)
  124. return -EBUSY;
  125. for (;;) {
  126. char c;
  127. if (!indx)
  128. break;
  129. if (get_user(c, buf))
  130. return -EFAULT;
  131. if (esc) {
  132. set_led(c);
  133. esc = 0;
  134. } else if (c == 27) {
  135. esc = 1;
  136. } else if (c == 12) {
  137. /* do a form feed */
  138. for (i=0; i<40; i++)
  139. vfd[i] = ' ';
  140. vfd_cursor = 0;
  141. } else if (c == 10) {
  142. if (vfd_cursor < 20)
  143. vfd_cursor = 20;
  144. else if (vfd_cursor < 40)
  145. vfd_cursor = 40;
  146. else if (vfd_cursor < 60)
  147. vfd_cursor = 60;
  148. if (vfd_cursor > 59)
  149. scroll_vfd();
  150. } else {
  151. /* just a character */
  152. if (vfd_cursor > 39)
  153. scroll_vfd();
  154. vfd[vfd_cursor++] = c;
  155. }
  156. indx--;
  157. buf++;
  158. }
  159. update_vfd();
  160. return len;
  161. }
  162. static const struct file_operations briq_panel_fops = {
  163. .owner = THIS_MODULE,
  164. .read = briq_panel_read,
  165. .write = briq_panel_write,
  166. .open = briq_panel_open,
  167. .release = briq_panel_release,
  168. };
  169. static struct miscdevice briq_panel_miscdev = {
  170. BRIQ_PANEL_MINOR,
  171. "briq_panel",
  172. &briq_panel_fops
  173. };
  174. static int __init briq_panel_init(void)
  175. {
  176. struct device_node *root = find_path_device("/");
  177. const char *machine;
  178. int i;
  179. machine = get_property(root, "model", NULL);
  180. if (!machine || strncmp(machine, "TotalImpact,BRIQ-1", 18) != 0)
  181. return -ENODEV;
  182. printk(KERN_INFO
  183. "briq_panel: v%s Dr. Karsten Jeppesen (kj@totalimpact.com)\n",
  184. BRIQ_PANEL_VER);
  185. if (!request_region(BRIQ_PANEL_VFD_IOPORT, 4, "BRIQ Front Panel"))
  186. return -EBUSY;
  187. if (!request_region(BRIQ_PANEL_LED_IOPORT, 2, "BRIQ Front Panel")) {
  188. release_region(BRIQ_PANEL_VFD_IOPORT, 4);
  189. return -EBUSY;
  190. }
  191. ledpb = inb(BRIQ_PANEL_LED_IOPORT) & 0x000c;
  192. if (misc_register(&briq_panel_miscdev) < 0) {
  193. release_region(BRIQ_PANEL_VFD_IOPORT, 4);
  194. release_region(BRIQ_PANEL_LED_IOPORT, 2);
  195. return -EBUSY;
  196. }
  197. outb(0x38, BRIQ_PANEL_VFD_IOPORT); /* Function set */
  198. outb(0x01, BRIQ_PANEL_VFD_IOPORT); /* Clear display */
  199. outb(0x0c, BRIQ_PANEL_VFD_IOPORT); /* Display on */
  200. outb(0x06, BRIQ_PANEL_VFD_IOPORT); /* Entry normal */
  201. for (i=0; i<40; i++)
  202. vfd[i]=' ';
  203. #ifndef MODULE
  204. vfd[0] = 'L';
  205. vfd[1] = 'o';
  206. vfd[2] = 'a';
  207. vfd[3] = 'd';
  208. vfd[4] = 'i';
  209. vfd[5] = 'n';
  210. vfd[6] = 'g';
  211. vfd[7] = ' ';
  212. vfd[8] = '.';
  213. vfd[9] = '.';
  214. vfd[10] = '.';
  215. #endif /* !MODULE */
  216. update_vfd();
  217. return 0;
  218. }
  219. static void __exit briq_panel_exit(void)
  220. {
  221. misc_deregister(&briq_panel_miscdev);
  222. release_region(BRIQ_PANEL_VFD_IOPORT, 4);
  223. release_region(BRIQ_PANEL_LED_IOPORT, 2);
  224. }
  225. module_init(briq_panel_init);
  226. module_exit(briq_panel_exit);
  227. MODULE_LICENSE("GPL");
  228. MODULE_AUTHOR("Karsten Jeppesen <karsten@jeppesens.com>");
  229. MODULE_DESCRIPTION("Driver for the Total Impact briQ front panel");