briq_panel.c 5.2 KB

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