suncore.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /* suncore.c
  2. *
  3. * Common SUN serial routines. Based entirely
  4. * upon drivers/sbus/char/sunserial.c which is:
  5. *
  6. * Copyright (C) 1997 Eddie C. Dost (ecd@skynet.be)
  7. *
  8. * Adaptation to new UART layer is:
  9. *
  10. * Copyright (C) 2002 David S. Miller (davem@redhat.com)
  11. */
  12. #include <linux/config.h>
  13. #include <linux/module.h>
  14. #include <linux/kernel.h>
  15. #include <linux/console.h>
  16. #include <linux/tty.h>
  17. #include <linux/errno.h>
  18. #include <linux/string.h>
  19. #include <linux/init.h>
  20. #include <asm/oplib.h>
  21. #include "suncore.h"
  22. int sunserial_current_minor = 64;
  23. EXPORT_SYMBOL(sunserial_current_minor);
  24. void
  25. sunserial_console_termios(struct console *con)
  26. {
  27. char mode[16], buf[16], *s;
  28. char *mode_prop = "ttyX-mode";
  29. char *cd_prop = "ttyX-ignore-cd";
  30. char *dtr_prop = "ttyX-rts-dtr-off";
  31. char *ssp_console_modes_prop = "ssp-console-modes";
  32. int baud, bits, stop, cflag;
  33. char parity;
  34. int carrier = 0;
  35. int rtsdtr = 1;
  36. int topnd, nd;
  37. if (!serial_console)
  38. return;
  39. switch (serial_console) {
  40. case PROMDEV_OTTYA:
  41. mode_prop[3] = 'a';
  42. cd_prop[3] = 'a';
  43. dtr_prop[3] = 'a';
  44. break;
  45. case PROMDEV_OTTYB:
  46. mode_prop[3] = 'b';
  47. cd_prop[3] = 'b';
  48. dtr_prop[3] = 'b';
  49. break;
  50. case PROMDEV_ORSC:
  51. nd = prom_pathtoinode("rsc");
  52. if (!nd) {
  53. strcpy(mode, "115200,8,n,1,-");
  54. goto no_options;
  55. }
  56. if (!prom_node_has_property(nd, ssp_console_modes_prop)) {
  57. strcpy(mode, "115200,8,n,1,-");
  58. goto no_options;
  59. }
  60. memset(mode, 0, sizeof(mode));
  61. prom_getstring(nd, ssp_console_modes_prop, mode, sizeof(mode));
  62. goto no_options;
  63. default:
  64. strcpy(mode, "9600,8,n,1,-");
  65. goto no_options;
  66. }
  67. topnd = prom_getchild(prom_root_node);
  68. nd = prom_searchsiblings(topnd, "options");
  69. if (!nd) {
  70. strcpy(mode, "9600,8,n,1,-");
  71. goto no_options;
  72. }
  73. if (!prom_node_has_property(nd, mode_prop)) {
  74. strcpy(mode, "9600,8,n,1,-");
  75. goto no_options;
  76. }
  77. memset(mode, 0, sizeof(mode));
  78. prom_getstring(nd, mode_prop, mode, sizeof(mode));
  79. if (prom_node_has_property(nd, cd_prop)) {
  80. memset(buf, 0, sizeof(buf));
  81. prom_getstring(nd, cd_prop, buf, sizeof(buf));
  82. if (!strcmp(buf, "false"))
  83. carrier = 1;
  84. /* XXX: this is unused below. */
  85. }
  86. if (prom_node_has_property(nd, dtr_prop)) {
  87. memset(buf, 0, sizeof(buf));
  88. prom_getstring(nd, dtr_prop, buf, sizeof(buf));
  89. if (!strcmp(buf, "false"))
  90. rtsdtr = 0;
  91. /* XXX: this is unused below. */
  92. }
  93. no_options:
  94. cflag = CREAD | HUPCL | CLOCAL;
  95. s = mode;
  96. baud = simple_strtoul(s, NULL, 0);
  97. s = strchr(s, ',');
  98. bits = simple_strtoul(++s, NULL, 0);
  99. s = strchr(s, ',');
  100. parity = *(++s);
  101. s = strchr(s, ',');
  102. stop = simple_strtoul(++s, NULL, 0);
  103. s = strchr(s, ',');
  104. /* XXX handshake is not handled here. */
  105. switch (baud) {
  106. case 150: cflag |= B150; break;
  107. case 300: cflag |= B300; break;
  108. case 600: cflag |= B600; break;
  109. case 1200: cflag |= B1200; break;
  110. case 2400: cflag |= B2400; break;
  111. case 4800: cflag |= B4800; break;
  112. case 9600: cflag |= B9600; break;
  113. case 19200: cflag |= B19200; break;
  114. case 38400: cflag |= B38400; break;
  115. case 57600: cflag |= B57600; break;
  116. case 115200: cflag |= B115200; break;
  117. case 230400: cflag |= B230400; break;
  118. case 460800: cflag |= B460800; break;
  119. default: baud = 9600; cflag |= B9600; break;
  120. }
  121. switch (bits) {
  122. case 5: cflag |= CS5; break;
  123. case 6: cflag |= CS6; break;
  124. case 7: cflag |= CS7; break;
  125. case 8: cflag |= CS8; break;
  126. default: cflag |= CS8; break;
  127. }
  128. switch (parity) {
  129. case 'o': cflag |= (PARENB | PARODD); break;
  130. case 'e': cflag |= PARENB; break;
  131. case 'n': default: break;
  132. }
  133. switch (stop) {
  134. case 2: cflag |= CSTOPB; break;
  135. case 1: default: break;
  136. }
  137. con->cflag = cflag;
  138. }
  139. EXPORT_SYMBOL(sunserial_console_termios);
  140. /* Sun serial MOUSE auto baud rate detection. */
  141. static struct mouse_baud_cflag {
  142. int baud;
  143. unsigned int cflag;
  144. } mouse_baud_table[] = {
  145. { 1200, B1200 },
  146. { 2400, B2400 },
  147. { 4800, B4800 },
  148. { 9600, B9600 },
  149. { -1, ~0 },
  150. { -1, ~0 },
  151. };
  152. unsigned int suncore_mouse_baud_cflag_next(unsigned int cflag, int *new_baud)
  153. {
  154. int i;
  155. for (i = 0; mouse_baud_table[i].baud != -1; i++)
  156. if (mouse_baud_table[i].cflag == (cflag & CBAUD))
  157. break;
  158. i += 1;
  159. if (mouse_baud_table[i].baud == -1)
  160. i = 0;
  161. *new_baud = mouse_baud_table[i].baud;
  162. return mouse_baud_table[i].cflag;
  163. }
  164. EXPORT_SYMBOL(suncore_mouse_baud_cflag_next);
  165. /* Basically, when the baud rate is wrong the mouse spits out
  166. * breaks to us.
  167. */
  168. int suncore_mouse_baud_detection(unsigned char ch, int is_break)
  169. {
  170. static int mouse_got_break = 0;
  171. static int ctr = 0;
  172. if (is_break) {
  173. /* Let a few normal bytes go by before we jump the gun
  174. * and say we need to try another baud rate.
  175. */
  176. if (mouse_got_break && ctr < 8)
  177. return 1;
  178. /* Ok, we need to try another baud. */
  179. ctr = 0;
  180. mouse_got_break = 1;
  181. return 2;
  182. }
  183. if (mouse_got_break) {
  184. ctr++;
  185. if (ch == 0x87) {
  186. /* Correct baud rate determined. */
  187. mouse_got_break = 0;
  188. }
  189. return 1;
  190. }
  191. return 0;
  192. }
  193. EXPORT_SYMBOL(suncore_mouse_baud_detection);
  194. static int __init suncore_init(void)
  195. {
  196. return 0;
  197. }
  198. static void __exit suncore_exit(void)
  199. {
  200. }
  201. module_init(suncore_init);
  202. module_exit(suncore_exit);
  203. MODULE_AUTHOR("Eddie C. Dost, David S. Miller");
  204. MODULE_DESCRIPTION("Sun serial common layer");
  205. MODULE_LICENSE("GPL");