briq_panel.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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/smp_lock.h>
  8. #include <linux/types.h>
  9. #include <linux/errno.h>
  10. #include <linux/tty.h>
  11. #include <linux/timer.h>
  12. #include <linux/kernel.h>
  13. #include <linux/wait.h>
  14. #include <linux/string.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. lock_kernel();
  60. /* enforce single access, vfd_is_open is protected by BKL */
  61. if (vfd_is_open) {
  62. unlock_kernel();
  63. return -EBUSY;
  64. }
  65. vfd_is_open = 1;
  66. unlock_kernel();
  67. return 0;
  68. }
  69. static int briq_panel_release(struct inode *ino, struct file *filep)
  70. {
  71. if (!vfd_is_open)
  72. return -ENODEV;
  73. vfd_is_open = 0;
  74. return 0;
  75. }
  76. static ssize_t briq_panel_read(struct file *file, char __user *buf, size_t count,
  77. loff_t *ppos)
  78. {
  79. unsigned short c;
  80. unsigned char cp;
  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 (!vfd_is_open)
  120. return -EBUSY;
  121. for (;;) {
  122. char c;
  123. if (!indx)
  124. break;
  125. if (get_user(c, buf))
  126. return -EFAULT;
  127. if (esc) {
  128. set_led(c);
  129. esc = 0;
  130. } else if (c == 27) {
  131. esc = 1;
  132. } else if (c == 12) {
  133. /* do a form feed */
  134. for (i=0; i<40; i++)
  135. vfd[i] = ' ';
  136. vfd_cursor = 0;
  137. } else if (c == 10) {
  138. if (vfd_cursor < 20)
  139. vfd_cursor = 20;
  140. else if (vfd_cursor < 40)
  141. vfd_cursor = 40;
  142. else if (vfd_cursor < 60)
  143. vfd_cursor = 60;
  144. if (vfd_cursor > 59)
  145. scroll_vfd();
  146. } else {
  147. /* just a character */
  148. if (vfd_cursor > 39)
  149. scroll_vfd();
  150. vfd[vfd_cursor++] = c;
  151. }
  152. indx--;
  153. buf++;
  154. }
  155. update_vfd();
  156. return len;
  157. }
  158. static const struct file_operations briq_panel_fops = {
  159. .owner = THIS_MODULE,
  160. .read = briq_panel_read,
  161. .write = briq_panel_write,
  162. .open = briq_panel_open,
  163. .release = briq_panel_release,
  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");