briq_panel.c 5.3 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/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/slab.h>
  16. #include <linux/ioport.h>
  17. #include <linux/delay.h>
  18. #include <linux/miscdevice.h>
  19. #include <linux/fs.h>
  20. #include <linux/mm.h>
  21. #include <linux/init.h>
  22. #include <asm/uaccess.h>
  23. #include <asm/io.h>
  24. #include <asm/prom.h>
  25. #define BRIQ_PANEL_MINOR 156
  26. #define BRIQ_PANEL_VFD_IOPORT 0x0390
  27. #define BRIQ_PANEL_LED_IOPORT 0x0398
  28. #define BRIQ_PANEL_VER "1.1 (04/20/2002)"
  29. #define BRIQ_PANEL_MSG0 "Loading Linux"
  30. static int vfd_is_open;
  31. static unsigned char vfd[40];
  32. static int vfd_cursor;
  33. static unsigned char ledpb, led;
  34. static void update_vfd(void)
  35. {
  36. int i;
  37. /* cursor home */
  38. outb(0x02, BRIQ_PANEL_VFD_IOPORT);
  39. for (i=0; i<20; i++)
  40. outb(vfd[i], BRIQ_PANEL_VFD_IOPORT + 1);
  41. /* cursor to next line */
  42. outb(0xc0, BRIQ_PANEL_VFD_IOPORT);
  43. for (i=20; i<40; i++)
  44. outb(vfd[i], BRIQ_PANEL_VFD_IOPORT + 1);
  45. }
  46. static void set_led(char state)
  47. {
  48. if (state == 'R')
  49. led = 0x01;
  50. else if (state == 'G')
  51. led = 0x02;
  52. else if (state == 'Y')
  53. led = 0x03;
  54. else if (state == 'X')
  55. led = 0x00;
  56. outb(led, BRIQ_PANEL_LED_IOPORT);
  57. }
  58. static int briq_panel_open(struct inode *ino, struct file *filep)
  59. {
  60. lock_kernel();
  61. /* enforce single access, vfd_is_open is protected by BKL */
  62. if (vfd_is_open) {
  63. unlock_kernel();
  64. return -EBUSY;
  65. }
  66. vfd_is_open = 1;
  67. unlock_kernel();
  68. return 0;
  69. }
  70. static int briq_panel_release(struct inode *ino, struct file *filep)
  71. {
  72. if (!vfd_is_open)
  73. return -ENODEV;
  74. vfd_is_open = 0;
  75. return 0;
  76. }
  77. static ssize_t briq_panel_read(struct file *file, char __user *buf, size_t count,
  78. loff_t *ppos)
  79. {
  80. unsigned short c;
  81. unsigned char cp;
  82. if (!vfd_is_open)
  83. return -ENODEV;
  84. c = (inb(BRIQ_PANEL_LED_IOPORT) & 0x000c) | (ledpb & 0x0003);
  85. set_led(' ');
  86. /* upper button released */
  87. if ((!(ledpb & 0x0004)) && (c & 0x0004)) {
  88. cp = ' ';
  89. ledpb = c;
  90. if (copy_to_user(buf, &cp, 1))
  91. return -EFAULT;
  92. return 1;
  93. }
  94. /* lower button released */
  95. else if ((!(ledpb & 0x0008)) && (c & 0x0008)) {
  96. cp = '\r';
  97. ledpb = c;
  98. if (copy_to_user(buf, &cp, 1))
  99. return -EFAULT;
  100. return 1;
  101. } else {
  102. ledpb = c;
  103. return 0;
  104. }
  105. }
  106. static void scroll_vfd( void )
  107. {
  108. int i;
  109. for (i=0; i<20; i++) {
  110. vfd[i] = vfd[i+20];
  111. vfd[i+20] = ' ';
  112. }
  113. vfd_cursor = 20;
  114. }
  115. static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_t len,
  116. loff_t *ppos)
  117. {
  118. size_t indx = len;
  119. int i, esc = 0;
  120. if (!vfd_is_open)
  121. return -EBUSY;
  122. for (;;) {
  123. char c;
  124. if (!indx)
  125. break;
  126. if (get_user(c, buf))
  127. return -EFAULT;
  128. if (esc) {
  129. set_led(c);
  130. esc = 0;
  131. } else if (c == 27) {
  132. esc = 1;
  133. } else if (c == 12) {
  134. /* do a form feed */
  135. for (i=0; i<40; i++)
  136. vfd[i] = ' ';
  137. vfd_cursor = 0;
  138. } else if (c == 10) {
  139. if (vfd_cursor < 20)
  140. vfd_cursor = 20;
  141. else if (vfd_cursor < 40)
  142. vfd_cursor = 40;
  143. else if (vfd_cursor < 60)
  144. vfd_cursor = 60;
  145. if (vfd_cursor > 59)
  146. scroll_vfd();
  147. } else {
  148. /* just a character */
  149. if (vfd_cursor > 39)
  150. scroll_vfd();
  151. vfd[vfd_cursor++] = c;
  152. }
  153. indx--;
  154. buf++;
  155. }
  156. update_vfd();
  157. return len;
  158. }
  159. static const struct file_operations briq_panel_fops = {
  160. .owner = THIS_MODULE,
  161. .read = briq_panel_read,
  162. .write = briq_panel_write,
  163. .open = briq_panel_open,
  164. .release = briq_panel_release,
  165. };
  166. static struct miscdevice briq_panel_miscdev = {
  167. BRIQ_PANEL_MINOR,
  168. "briq_panel",
  169. &briq_panel_fops
  170. };
  171. static int __init briq_panel_init(void)
  172. {
  173. struct device_node *root = of_find_node_by_path("/");
  174. const char *machine;
  175. int i;
  176. machine = of_get_property(root, "model", NULL);
  177. if (!machine || strncmp(machine, "TotalImpact,BRIQ-1", 18) != 0) {
  178. of_node_put(root);
  179. return -ENODEV;
  180. }
  181. of_node_put(root);
  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");