ip22zilog.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215
  1. /*
  2. * Driver for Zilog serial chips found on SGI workstations and
  3. * servers. This driver could actually be made more generic.
  4. *
  5. * This is based on the drivers/serial/sunzilog.c code as of 2.6.0-test7 and the
  6. * old drivers/sgi/char/sgiserial.c code which itself is based of the original
  7. * drivers/sbus/char/zs.c code. A lot of code has been simply moved over
  8. * directly from there but much has been rewritten. Credits therefore go out
  9. * to David S. Miller, Eddie C. Dost, Pete Zaitcev, Ted Ts'o and Alex Buell
  10. * for their work there.
  11. *
  12. * Copyright (C) 2002 Ralf Baechle (ralf@linux-mips.org)
  13. * Copyright (C) 2002 David S. Miller (davem@redhat.com)
  14. */
  15. #include <linux/module.h>
  16. #include <linux/kernel.h>
  17. #include <linux/errno.h>
  18. #include <linux/delay.h>
  19. #include <linux/tty.h>
  20. #include <linux/tty_flip.h>
  21. #include <linux/major.h>
  22. #include <linux/string.h>
  23. #include <linux/ptrace.h>
  24. #include <linux/ioport.h>
  25. #include <linux/slab.h>
  26. #include <linux/circ_buf.h>
  27. #include <linux/serial.h>
  28. #include <linux/sysrq.h>
  29. #include <linux/console.h>
  30. #include <linux/spinlock.h>
  31. #include <linux/init.h>
  32. #include <asm/io.h>
  33. #include <asm/irq.h>
  34. #include <asm/sgialib.h>
  35. #include <asm/sgi/ioc.h>
  36. #include <asm/sgi/hpc3.h>
  37. #include <asm/sgi/ip22.h>
  38. #if defined(CONFIG_SERIAL_IP22_ZILOG_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
  39. #define SUPPORT_SYSRQ
  40. #endif
  41. #include <linux/serial_core.h>
  42. #include "ip22zilog.h"
  43. /*
  44. * On IP22 we need to delay after register accesses but we do not need to
  45. * flush writes.
  46. */
  47. #define ZSDELAY() udelay(5)
  48. #define ZSDELAY_LONG() udelay(20)
  49. #define ZS_WSYNC(channel) do { } while (0)
  50. #define NUM_IP22ZILOG 1
  51. #define NUM_CHANNELS (NUM_IP22ZILOG * 2)
  52. #define ZS_CLOCK 3672000 /* Zilog input clock rate. */
  53. #define ZS_CLOCK_DIVISOR 16 /* Divisor this driver uses. */
  54. /*
  55. * We wrap our port structure around the generic uart_port.
  56. */
  57. struct uart_ip22zilog_port {
  58. struct uart_port port;
  59. /* IRQ servicing chain. */
  60. struct uart_ip22zilog_port *next;
  61. /* Current values of Zilog write registers. */
  62. unsigned char curregs[NUM_ZSREGS];
  63. unsigned int flags;
  64. #define IP22ZILOG_FLAG_IS_CONS 0x00000004
  65. #define IP22ZILOG_FLAG_IS_KGDB 0x00000008
  66. #define IP22ZILOG_FLAG_MODEM_STATUS 0x00000010
  67. #define IP22ZILOG_FLAG_IS_CHANNEL_A 0x00000020
  68. #define IP22ZILOG_FLAG_REGS_HELD 0x00000040
  69. #define IP22ZILOG_FLAG_TX_STOPPED 0x00000080
  70. #define IP22ZILOG_FLAG_TX_ACTIVE 0x00000100
  71. #define IP22ZILOG_FLAG_RESET_DONE 0x00000200
  72. unsigned int tty_break;
  73. unsigned char parity_mask;
  74. unsigned char prev_status;
  75. };
  76. #define ZILOG_CHANNEL_FROM_PORT(PORT) ((struct zilog_channel *)((PORT)->membase))
  77. #define UART_ZILOG(PORT) ((struct uart_ip22zilog_port *)(PORT))
  78. #define IP22ZILOG_GET_CURR_REG(PORT, REGNUM) \
  79. (UART_ZILOG(PORT)->curregs[REGNUM])
  80. #define IP22ZILOG_SET_CURR_REG(PORT, REGNUM, REGVAL) \
  81. ((UART_ZILOG(PORT)->curregs[REGNUM]) = (REGVAL))
  82. #define ZS_IS_CONS(UP) ((UP)->flags & IP22ZILOG_FLAG_IS_CONS)
  83. #define ZS_IS_KGDB(UP) ((UP)->flags & IP22ZILOG_FLAG_IS_KGDB)
  84. #define ZS_WANTS_MODEM_STATUS(UP) ((UP)->flags & IP22ZILOG_FLAG_MODEM_STATUS)
  85. #define ZS_IS_CHANNEL_A(UP) ((UP)->flags & IP22ZILOG_FLAG_IS_CHANNEL_A)
  86. #define ZS_REGS_HELD(UP) ((UP)->flags & IP22ZILOG_FLAG_REGS_HELD)
  87. #define ZS_TX_STOPPED(UP) ((UP)->flags & IP22ZILOG_FLAG_TX_STOPPED)
  88. #define ZS_TX_ACTIVE(UP) ((UP)->flags & IP22ZILOG_FLAG_TX_ACTIVE)
  89. /* Reading and writing Zilog8530 registers. The delays are to make this
  90. * driver work on the IP22 which needs a settling delay after each chip
  91. * register access, other machines handle this in hardware via auxiliary
  92. * flip-flops which implement the settle time we do in software.
  93. *
  94. * The port lock must be held and local IRQs must be disabled
  95. * when {read,write}_zsreg is invoked.
  96. */
  97. static unsigned char read_zsreg(struct zilog_channel *channel,
  98. unsigned char reg)
  99. {
  100. unsigned char retval;
  101. writeb(reg, &channel->control);
  102. ZSDELAY();
  103. retval = readb(&channel->control);
  104. ZSDELAY();
  105. return retval;
  106. }
  107. static void write_zsreg(struct zilog_channel *channel,
  108. unsigned char reg, unsigned char value)
  109. {
  110. writeb(reg, &channel->control);
  111. ZSDELAY();
  112. writeb(value, &channel->control);
  113. ZSDELAY();
  114. }
  115. static void ip22zilog_clear_fifo(struct zilog_channel *channel)
  116. {
  117. int i;
  118. for (i = 0; i < 32; i++) {
  119. unsigned char regval;
  120. regval = readb(&channel->control);
  121. ZSDELAY();
  122. if (regval & Rx_CH_AV)
  123. break;
  124. regval = read_zsreg(channel, R1);
  125. readb(&channel->data);
  126. ZSDELAY();
  127. if (regval & (PAR_ERR | Rx_OVR | CRC_ERR)) {
  128. writeb(ERR_RES, &channel->control);
  129. ZSDELAY();
  130. ZS_WSYNC(channel);
  131. }
  132. }
  133. }
  134. /* This function must only be called when the TX is not busy. The UART
  135. * port lock must be held and local interrupts disabled.
  136. */
  137. static void __load_zsregs(struct zilog_channel *channel, unsigned char *regs)
  138. {
  139. int i;
  140. /* Let pending transmits finish. */
  141. for (i = 0; i < 1000; i++) {
  142. unsigned char stat = read_zsreg(channel, R1);
  143. if (stat & ALL_SNT)
  144. break;
  145. udelay(100);
  146. }
  147. writeb(ERR_RES, &channel->control);
  148. ZSDELAY();
  149. ZS_WSYNC(channel);
  150. ip22zilog_clear_fifo(channel);
  151. /* Disable all interrupts. */
  152. write_zsreg(channel, R1,
  153. regs[R1] & ~(RxINT_MASK | TxINT_ENAB | EXT_INT_ENAB));
  154. /* Set parity, sync config, stop bits, and clock divisor. */
  155. write_zsreg(channel, R4, regs[R4]);
  156. /* Set misc. TX/RX control bits. */
  157. write_zsreg(channel, R10, regs[R10]);
  158. /* Set TX/RX controls sans the enable bits. */
  159. write_zsreg(channel, R3, regs[R3] & ~RxENAB);
  160. write_zsreg(channel, R5, regs[R5] & ~TxENAB);
  161. /* Synchronous mode config. */
  162. write_zsreg(channel, R6, regs[R6]);
  163. write_zsreg(channel, R7, regs[R7]);
  164. /* Don't mess with the interrupt vector (R2, unused by us) and
  165. * master interrupt control (R9). We make sure this is setup
  166. * properly at probe time then never touch it again.
  167. */
  168. /* Disable baud generator. */
  169. write_zsreg(channel, R14, regs[R14] & ~BRENAB);
  170. /* Clock mode control. */
  171. write_zsreg(channel, R11, regs[R11]);
  172. /* Lower and upper byte of baud rate generator divisor. */
  173. write_zsreg(channel, R12, regs[R12]);
  174. write_zsreg(channel, R13, regs[R13]);
  175. /* Now rewrite R14, with BRENAB (if set). */
  176. write_zsreg(channel, R14, regs[R14]);
  177. /* External status interrupt control. */
  178. write_zsreg(channel, R15, regs[R15]);
  179. /* Reset external status interrupts. */
  180. write_zsreg(channel, R0, RES_EXT_INT);
  181. write_zsreg(channel, R0, RES_EXT_INT);
  182. /* Rewrite R3/R5, this time without enables masked. */
  183. write_zsreg(channel, R3, regs[R3]);
  184. write_zsreg(channel, R5, regs[R5]);
  185. /* Rewrite R1, this time without IRQ enabled masked. */
  186. write_zsreg(channel, R1, regs[R1]);
  187. }
  188. /* Reprogram the Zilog channel HW registers with the copies found in the
  189. * software state struct. If the transmitter is busy, we defer this update
  190. * until the next TX complete interrupt. Else, we do it right now.
  191. *
  192. * The UART port lock must be held and local interrupts disabled.
  193. */
  194. static void ip22zilog_maybe_update_regs(struct uart_ip22zilog_port *up,
  195. struct zilog_channel *channel)
  196. {
  197. if (!ZS_REGS_HELD(up)) {
  198. if (ZS_TX_ACTIVE(up)) {
  199. up->flags |= IP22ZILOG_FLAG_REGS_HELD;
  200. } else {
  201. __load_zsregs(channel, up->curregs);
  202. }
  203. }
  204. }
  205. #define Rx_BRK 0x0100 /* BREAK event software flag. */
  206. #define Rx_SYS 0x0200 /* SysRq event software flag. */
  207. static bool ip22zilog_receive_chars(struct uart_ip22zilog_port *up,
  208. struct zilog_channel *channel)
  209. {
  210. unsigned char ch, flag;
  211. unsigned int r1;
  212. bool push = up->port.state != NULL;
  213. for (;;) {
  214. ch = readb(&channel->control);
  215. ZSDELAY();
  216. if (!(ch & Rx_CH_AV))
  217. break;
  218. r1 = read_zsreg(channel, R1);
  219. if (r1 & (PAR_ERR | Rx_OVR | CRC_ERR)) {
  220. writeb(ERR_RES, &channel->control);
  221. ZSDELAY();
  222. ZS_WSYNC(channel);
  223. }
  224. ch = readb(&channel->data);
  225. ZSDELAY();
  226. ch &= up->parity_mask;
  227. /* Handle the null char got when BREAK is removed. */
  228. if (!ch)
  229. r1 |= up->tty_break;
  230. /* A real serial line, record the character and status. */
  231. flag = TTY_NORMAL;
  232. up->port.icount.rx++;
  233. if (r1 & (PAR_ERR | Rx_OVR | CRC_ERR | Rx_SYS | Rx_BRK)) {
  234. up->tty_break = 0;
  235. if (r1 & (Rx_SYS | Rx_BRK)) {
  236. up->port.icount.brk++;
  237. if (r1 & Rx_SYS)
  238. continue;
  239. r1 &= ~(PAR_ERR | CRC_ERR);
  240. }
  241. else if (r1 & PAR_ERR)
  242. up->port.icount.parity++;
  243. else if (r1 & CRC_ERR)
  244. up->port.icount.frame++;
  245. if (r1 & Rx_OVR)
  246. up->port.icount.overrun++;
  247. r1 &= up->port.read_status_mask;
  248. if (r1 & Rx_BRK)
  249. flag = TTY_BREAK;
  250. else if (r1 & PAR_ERR)
  251. flag = TTY_PARITY;
  252. else if (r1 & CRC_ERR)
  253. flag = TTY_FRAME;
  254. }
  255. if (uart_handle_sysrq_char(&up->port, ch))
  256. continue;
  257. if (push)
  258. uart_insert_char(&up->port, r1, Rx_OVR, ch, flag);
  259. }
  260. return push;
  261. }
  262. static void ip22zilog_status_handle(struct uart_ip22zilog_port *up,
  263. struct zilog_channel *channel)
  264. {
  265. unsigned char status;
  266. status = readb(&channel->control);
  267. ZSDELAY();
  268. writeb(RES_EXT_INT, &channel->control);
  269. ZSDELAY();
  270. ZS_WSYNC(channel);
  271. if (up->curregs[R15] & BRKIE) {
  272. if ((status & BRK_ABRT) && !(up->prev_status & BRK_ABRT)) {
  273. if (uart_handle_break(&up->port))
  274. up->tty_break = Rx_SYS;
  275. else
  276. up->tty_break = Rx_BRK;
  277. }
  278. }
  279. if (ZS_WANTS_MODEM_STATUS(up)) {
  280. if (status & SYNC)
  281. up->port.icount.dsr++;
  282. /* The Zilog just gives us an interrupt when DCD/CTS/etc. change.
  283. * But it does not tell us which bit has changed, we have to keep
  284. * track of this ourselves.
  285. */
  286. if ((status ^ up->prev_status) ^ DCD)
  287. uart_handle_dcd_change(&up->port,
  288. (status & DCD));
  289. if ((status ^ up->prev_status) ^ CTS)
  290. uart_handle_cts_change(&up->port,
  291. (status & CTS));
  292. wake_up_interruptible(&up->port.state->port.delta_msr_wait);
  293. }
  294. up->prev_status = status;
  295. }
  296. static void ip22zilog_transmit_chars(struct uart_ip22zilog_port *up,
  297. struct zilog_channel *channel)
  298. {
  299. struct circ_buf *xmit;
  300. if (ZS_IS_CONS(up)) {
  301. unsigned char status = readb(&channel->control);
  302. ZSDELAY();
  303. /* TX still busy? Just wait for the next TX done interrupt.
  304. *
  305. * It can occur because of how we do serial console writes. It would
  306. * be nice to transmit console writes just like we normally would for
  307. * a TTY line. (ie. buffered and TX interrupt driven). That is not
  308. * easy because console writes cannot sleep. One solution might be
  309. * to poll on enough port->xmit space becoming free. -DaveM
  310. */
  311. if (!(status & Tx_BUF_EMP))
  312. return;
  313. }
  314. up->flags &= ~IP22ZILOG_FLAG_TX_ACTIVE;
  315. if (ZS_REGS_HELD(up)) {
  316. __load_zsregs(channel, up->curregs);
  317. up->flags &= ~IP22ZILOG_FLAG_REGS_HELD;
  318. }
  319. if (ZS_TX_STOPPED(up)) {
  320. up->flags &= ~IP22ZILOG_FLAG_TX_STOPPED;
  321. goto ack_tx_int;
  322. }
  323. if (up->port.x_char) {
  324. up->flags |= IP22ZILOG_FLAG_TX_ACTIVE;
  325. writeb(up->port.x_char, &channel->data);
  326. ZSDELAY();
  327. ZS_WSYNC(channel);
  328. up->port.icount.tx++;
  329. up->port.x_char = 0;
  330. return;
  331. }
  332. if (up->port.state == NULL)
  333. goto ack_tx_int;
  334. xmit = &up->port.state->xmit;
  335. if (uart_circ_empty(xmit))
  336. goto ack_tx_int;
  337. if (uart_tx_stopped(&up->port))
  338. goto ack_tx_int;
  339. up->flags |= IP22ZILOG_FLAG_TX_ACTIVE;
  340. writeb(xmit->buf[xmit->tail], &channel->data);
  341. ZSDELAY();
  342. ZS_WSYNC(channel);
  343. xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
  344. up->port.icount.tx++;
  345. if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
  346. uart_write_wakeup(&up->port);
  347. return;
  348. ack_tx_int:
  349. writeb(RES_Tx_P, &channel->control);
  350. ZSDELAY();
  351. ZS_WSYNC(channel);
  352. }
  353. static irqreturn_t ip22zilog_interrupt(int irq, void *dev_id)
  354. {
  355. struct uart_ip22zilog_port *up = dev_id;
  356. while (up) {
  357. struct zilog_channel *channel
  358. = ZILOG_CHANNEL_FROM_PORT(&up->port);
  359. unsigned char r3;
  360. bool push = false;
  361. spin_lock(&up->port.lock);
  362. r3 = read_zsreg(channel, R3);
  363. /* Channel A */
  364. if (r3 & (CHAEXT | CHATxIP | CHARxIP)) {
  365. writeb(RES_H_IUS, &channel->control);
  366. ZSDELAY();
  367. ZS_WSYNC(channel);
  368. if (r3 & CHARxIP)
  369. push = ip22zilog_receive_chars(up, channel);
  370. if (r3 & CHAEXT)
  371. ip22zilog_status_handle(up, channel);
  372. if (r3 & CHATxIP)
  373. ip22zilog_transmit_chars(up, channel);
  374. }
  375. spin_unlock(&up->port.lock);
  376. if (push)
  377. tty_flip_buffer_push(&up->port.state->port);
  378. /* Channel B */
  379. up = up->next;
  380. channel = ZILOG_CHANNEL_FROM_PORT(&up->port);
  381. push = false;
  382. spin_lock(&up->port.lock);
  383. if (r3 & (CHBEXT | CHBTxIP | CHBRxIP)) {
  384. writeb(RES_H_IUS, &channel->control);
  385. ZSDELAY();
  386. ZS_WSYNC(channel);
  387. if (r3 & CHBRxIP)
  388. push = ip22zilog_receive_chars(up, channel);
  389. if (r3 & CHBEXT)
  390. ip22zilog_status_handle(up, channel);
  391. if (r3 & CHBTxIP)
  392. ip22zilog_transmit_chars(up, channel);
  393. }
  394. spin_unlock(&up->port.lock);
  395. if (push)
  396. tty_flip_buffer_push(&up->port.state->port);
  397. up = up->next;
  398. }
  399. return IRQ_HANDLED;
  400. }
  401. /* A convenient way to quickly get R0 status. The caller must _not_ hold the
  402. * port lock, it is acquired here.
  403. */
  404. static __inline__ unsigned char ip22zilog_read_channel_status(struct uart_port *port)
  405. {
  406. struct zilog_channel *channel;
  407. unsigned char status;
  408. channel = ZILOG_CHANNEL_FROM_PORT(port);
  409. status = readb(&channel->control);
  410. ZSDELAY();
  411. return status;
  412. }
  413. /* The port lock is not held. */
  414. static unsigned int ip22zilog_tx_empty(struct uart_port *port)
  415. {
  416. unsigned long flags;
  417. unsigned char status;
  418. unsigned int ret;
  419. spin_lock_irqsave(&port->lock, flags);
  420. status = ip22zilog_read_channel_status(port);
  421. spin_unlock_irqrestore(&port->lock, flags);
  422. if (status & Tx_BUF_EMP)
  423. ret = TIOCSER_TEMT;
  424. else
  425. ret = 0;
  426. return ret;
  427. }
  428. /* The port lock is held and interrupts are disabled. */
  429. static unsigned int ip22zilog_get_mctrl(struct uart_port *port)
  430. {
  431. unsigned char status;
  432. unsigned int ret;
  433. status = ip22zilog_read_channel_status(port);
  434. ret = 0;
  435. if (status & DCD)
  436. ret |= TIOCM_CAR;
  437. if (status & SYNC)
  438. ret |= TIOCM_DSR;
  439. if (status & CTS)
  440. ret |= TIOCM_CTS;
  441. return ret;
  442. }
  443. /* The port lock is held and interrupts are disabled. */
  444. static void ip22zilog_set_mctrl(struct uart_port *port, unsigned int mctrl)
  445. {
  446. struct uart_ip22zilog_port *up = (struct uart_ip22zilog_port *) port;
  447. struct zilog_channel *channel = ZILOG_CHANNEL_FROM_PORT(port);
  448. unsigned char set_bits, clear_bits;
  449. set_bits = clear_bits = 0;
  450. if (mctrl & TIOCM_RTS)
  451. set_bits |= RTS;
  452. else
  453. clear_bits |= RTS;
  454. if (mctrl & TIOCM_DTR)
  455. set_bits |= DTR;
  456. else
  457. clear_bits |= DTR;
  458. /* NOTE: Not subject to 'transmitter active' rule. */
  459. up->curregs[R5] |= set_bits;
  460. up->curregs[R5] &= ~clear_bits;
  461. write_zsreg(channel, R5, up->curregs[R5]);
  462. }
  463. /* The port lock is held and interrupts are disabled. */
  464. static void ip22zilog_stop_tx(struct uart_port *port)
  465. {
  466. struct uart_ip22zilog_port *up = (struct uart_ip22zilog_port *) port;
  467. up->flags |= IP22ZILOG_FLAG_TX_STOPPED;
  468. }
  469. /* The port lock is held and interrupts are disabled. */
  470. static void ip22zilog_start_tx(struct uart_port *port)
  471. {
  472. struct uart_ip22zilog_port *up = (struct uart_ip22zilog_port *) port;
  473. struct zilog_channel *channel = ZILOG_CHANNEL_FROM_PORT(port);
  474. unsigned char status;
  475. up->flags |= IP22ZILOG_FLAG_TX_ACTIVE;
  476. up->flags &= ~IP22ZILOG_FLAG_TX_STOPPED;
  477. status = readb(&channel->control);
  478. ZSDELAY();
  479. /* TX busy? Just wait for the TX done interrupt. */
  480. if (!(status & Tx_BUF_EMP))
  481. return;
  482. /* Send the first character to jump-start the TX done
  483. * IRQ sending engine.
  484. */
  485. if (port->x_char) {
  486. writeb(port->x_char, &channel->data);
  487. ZSDELAY();
  488. ZS_WSYNC(channel);
  489. port->icount.tx++;
  490. port->x_char = 0;
  491. } else {
  492. struct circ_buf *xmit = &port->state->xmit;
  493. writeb(xmit->buf[xmit->tail], &channel->data);
  494. ZSDELAY();
  495. ZS_WSYNC(channel);
  496. xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
  497. port->icount.tx++;
  498. if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
  499. uart_write_wakeup(&up->port);
  500. }
  501. }
  502. /* The port lock is held and interrupts are disabled. */
  503. static void ip22zilog_stop_rx(struct uart_port *port)
  504. {
  505. struct uart_ip22zilog_port *up = UART_ZILOG(port);
  506. struct zilog_channel *channel;
  507. if (ZS_IS_CONS(up))
  508. return;
  509. channel = ZILOG_CHANNEL_FROM_PORT(port);
  510. /* Disable all RX interrupts. */
  511. up->curregs[R1] &= ~RxINT_MASK;
  512. ip22zilog_maybe_update_regs(up, channel);
  513. }
  514. /* The port lock is held. */
  515. static void ip22zilog_enable_ms(struct uart_port *port)
  516. {
  517. struct uart_ip22zilog_port *up = (struct uart_ip22zilog_port *) port;
  518. struct zilog_channel *channel = ZILOG_CHANNEL_FROM_PORT(port);
  519. unsigned char new_reg;
  520. new_reg = up->curregs[R15] | (DCDIE | SYNCIE | CTSIE);
  521. if (new_reg != up->curregs[R15]) {
  522. up->curregs[R15] = new_reg;
  523. /* NOTE: Not subject to 'transmitter active' rule. */
  524. write_zsreg(channel, R15, up->curregs[R15]);
  525. }
  526. }
  527. /* The port lock is not held. */
  528. static void ip22zilog_break_ctl(struct uart_port *port, int break_state)
  529. {
  530. struct uart_ip22zilog_port *up = (struct uart_ip22zilog_port *) port;
  531. struct zilog_channel *channel = ZILOG_CHANNEL_FROM_PORT(port);
  532. unsigned char set_bits, clear_bits, new_reg;
  533. unsigned long flags;
  534. set_bits = clear_bits = 0;
  535. if (break_state)
  536. set_bits |= SND_BRK;
  537. else
  538. clear_bits |= SND_BRK;
  539. spin_lock_irqsave(&port->lock, flags);
  540. new_reg = (up->curregs[R5] | set_bits) & ~clear_bits;
  541. if (new_reg != up->curregs[R5]) {
  542. up->curregs[R5] = new_reg;
  543. /* NOTE: Not subject to 'transmitter active' rule. */
  544. write_zsreg(channel, R5, up->curregs[R5]);
  545. }
  546. spin_unlock_irqrestore(&port->lock, flags);
  547. }
  548. static void __ip22zilog_reset(struct uart_ip22zilog_port *up)
  549. {
  550. struct zilog_channel *channel;
  551. int i;
  552. if (up->flags & IP22ZILOG_FLAG_RESET_DONE)
  553. return;
  554. /* Let pending transmits finish. */
  555. channel = ZILOG_CHANNEL_FROM_PORT(&up->port);
  556. for (i = 0; i < 1000; i++) {
  557. unsigned char stat = read_zsreg(channel, R1);
  558. if (stat & ALL_SNT)
  559. break;
  560. udelay(100);
  561. }
  562. if (!ZS_IS_CHANNEL_A(up)) {
  563. up++;
  564. channel = ZILOG_CHANNEL_FROM_PORT(&up->port);
  565. }
  566. write_zsreg(channel, R9, FHWRES);
  567. ZSDELAY_LONG();
  568. (void) read_zsreg(channel, R0);
  569. up->flags |= IP22ZILOG_FLAG_RESET_DONE;
  570. up->next->flags |= IP22ZILOG_FLAG_RESET_DONE;
  571. }
  572. static void __ip22zilog_startup(struct uart_ip22zilog_port *up)
  573. {
  574. struct zilog_channel *channel;
  575. channel = ZILOG_CHANNEL_FROM_PORT(&up->port);
  576. __ip22zilog_reset(up);
  577. __load_zsregs(channel, up->curregs);
  578. /* set master interrupt enable */
  579. write_zsreg(channel, R9, up->curregs[R9]);
  580. up->prev_status = readb(&channel->control);
  581. /* Enable receiver and transmitter. */
  582. up->curregs[R3] |= RxENAB;
  583. up->curregs[R5] |= TxENAB;
  584. up->curregs[R1] |= EXT_INT_ENAB | INT_ALL_Rx | TxINT_ENAB;
  585. ip22zilog_maybe_update_regs(up, channel);
  586. }
  587. static int ip22zilog_startup(struct uart_port *port)
  588. {
  589. struct uart_ip22zilog_port *up = UART_ZILOG(port);
  590. unsigned long flags;
  591. if (ZS_IS_CONS(up))
  592. return 0;
  593. spin_lock_irqsave(&port->lock, flags);
  594. __ip22zilog_startup(up);
  595. spin_unlock_irqrestore(&port->lock, flags);
  596. return 0;
  597. }
  598. /*
  599. * The test for ZS_IS_CONS is explained by the following e-mail:
  600. *****
  601. * From: Russell King <rmk@arm.linux.org.uk>
  602. * Date: Sun, 8 Dec 2002 10:18:38 +0000
  603. *
  604. * On Sun, Dec 08, 2002 at 02:43:36AM -0500, Pete Zaitcev wrote:
  605. * > I boot my 2.5 boxes using "console=ttyS0,9600" argument,
  606. * > and I noticed that something is not right with reference
  607. * > counting in this case. It seems that when the console
  608. * > is open by kernel initially, this is not accounted
  609. * > as an open, and uart_startup is not called.
  610. *
  611. * That is correct. We are unable to call uart_startup when the serial
  612. * console is initialised because it may need to allocate memory (as
  613. * request_irq does) and the memory allocators may not have been
  614. * initialised.
  615. *
  616. * 1. initialise the port into a state where it can send characters in the
  617. * console write method.
  618. *
  619. * 2. don't do the actual hardware shutdown in your shutdown() method (but
  620. * do the normal software shutdown - ie, free irqs etc)
  621. *****
  622. */
  623. static void ip22zilog_shutdown(struct uart_port *port)
  624. {
  625. struct uart_ip22zilog_port *up = UART_ZILOG(port);
  626. struct zilog_channel *channel;
  627. unsigned long flags;
  628. if (ZS_IS_CONS(up))
  629. return;
  630. spin_lock_irqsave(&port->lock, flags);
  631. channel = ZILOG_CHANNEL_FROM_PORT(port);
  632. /* Disable receiver and transmitter. */
  633. up->curregs[R3] &= ~RxENAB;
  634. up->curregs[R5] &= ~TxENAB;
  635. /* Disable all interrupts and BRK assertion. */
  636. up->curregs[R1] &= ~(EXT_INT_ENAB | TxINT_ENAB | RxINT_MASK);
  637. up->curregs[R5] &= ~SND_BRK;
  638. ip22zilog_maybe_update_regs(up, channel);
  639. spin_unlock_irqrestore(&port->lock, flags);
  640. }
  641. /* Shared by TTY driver and serial console setup. The port lock is held
  642. * and local interrupts are disabled.
  643. */
  644. static void
  645. ip22zilog_convert_to_zs(struct uart_ip22zilog_port *up, unsigned int cflag,
  646. unsigned int iflag, int brg)
  647. {
  648. up->curregs[R10] = NRZ;
  649. up->curregs[R11] = TCBR | RCBR;
  650. /* Program BAUD and clock source. */
  651. up->curregs[R4] &= ~XCLK_MASK;
  652. up->curregs[R4] |= X16CLK;
  653. up->curregs[R12] = brg & 0xff;
  654. up->curregs[R13] = (brg >> 8) & 0xff;
  655. up->curregs[R14] = BRENAB;
  656. /* Character size, stop bits, and parity. */
  657. up->curregs[3] &= ~RxN_MASK;
  658. up->curregs[5] &= ~TxN_MASK;
  659. switch (cflag & CSIZE) {
  660. case CS5:
  661. up->curregs[3] |= Rx5;
  662. up->curregs[5] |= Tx5;
  663. up->parity_mask = 0x1f;
  664. break;
  665. case CS6:
  666. up->curregs[3] |= Rx6;
  667. up->curregs[5] |= Tx6;
  668. up->parity_mask = 0x3f;
  669. break;
  670. case CS7:
  671. up->curregs[3] |= Rx7;
  672. up->curregs[5] |= Tx7;
  673. up->parity_mask = 0x7f;
  674. break;
  675. case CS8:
  676. default:
  677. up->curregs[3] |= Rx8;
  678. up->curregs[5] |= Tx8;
  679. up->parity_mask = 0xff;
  680. break;
  681. };
  682. up->curregs[4] &= ~0x0c;
  683. if (cflag & CSTOPB)
  684. up->curregs[4] |= SB2;
  685. else
  686. up->curregs[4] |= SB1;
  687. if (cflag & PARENB)
  688. up->curregs[4] |= PAR_ENAB;
  689. else
  690. up->curregs[4] &= ~PAR_ENAB;
  691. if (!(cflag & PARODD))
  692. up->curregs[4] |= PAR_EVEN;
  693. else
  694. up->curregs[4] &= ~PAR_EVEN;
  695. up->port.read_status_mask = Rx_OVR;
  696. if (iflag & INPCK)
  697. up->port.read_status_mask |= CRC_ERR | PAR_ERR;
  698. if (iflag & (BRKINT | PARMRK))
  699. up->port.read_status_mask |= BRK_ABRT;
  700. up->port.ignore_status_mask = 0;
  701. if (iflag & IGNPAR)
  702. up->port.ignore_status_mask |= CRC_ERR | PAR_ERR;
  703. if (iflag & IGNBRK) {
  704. up->port.ignore_status_mask |= BRK_ABRT;
  705. if (iflag & IGNPAR)
  706. up->port.ignore_status_mask |= Rx_OVR;
  707. }
  708. if ((cflag & CREAD) == 0)
  709. up->port.ignore_status_mask = 0xff;
  710. }
  711. /* The port lock is not held. */
  712. static void
  713. ip22zilog_set_termios(struct uart_port *port, struct ktermios *termios,
  714. struct ktermios *old)
  715. {
  716. struct uart_ip22zilog_port *up = (struct uart_ip22zilog_port *) port;
  717. unsigned long flags;
  718. int baud, brg;
  719. baud = uart_get_baud_rate(port, termios, old, 1200, 76800);
  720. spin_lock_irqsave(&up->port.lock, flags);
  721. brg = BPS_TO_BRG(baud, ZS_CLOCK / ZS_CLOCK_DIVISOR);
  722. ip22zilog_convert_to_zs(up, termios->c_cflag, termios->c_iflag, brg);
  723. if (UART_ENABLE_MS(&up->port, termios->c_cflag))
  724. up->flags |= IP22ZILOG_FLAG_MODEM_STATUS;
  725. else
  726. up->flags &= ~IP22ZILOG_FLAG_MODEM_STATUS;
  727. ip22zilog_maybe_update_regs(up, ZILOG_CHANNEL_FROM_PORT(port));
  728. uart_update_timeout(port, termios->c_cflag, baud);
  729. spin_unlock_irqrestore(&up->port.lock, flags);
  730. }
  731. static const char *ip22zilog_type(struct uart_port *port)
  732. {
  733. return "IP22-Zilog";
  734. }
  735. /* We do not request/release mappings of the registers here, this
  736. * happens at early serial probe time.
  737. */
  738. static void ip22zilog_release_port(struct uart_port *port)
  739. {
  740. }
  741. static int ip22zilog_request_port(struct uart_port *port)
  742. {
  743. return 0;
  744. }
  745. /* These do not need to do anything interesting either. */
  746. static void ip22zilog_config_port(struct uart_port *port, int flags)
  747. {
  748. }
  749. /* We do not support letting the user mess with the divisor, IRQ, etc. */
  750. static int ip22zilog_verify_port(struct uart_port *port, struct serial_struct *ser)
  751. {
  752. return -EINVAL;
  753. }
  754. static struct uart_ops ip22zilog_pops = {
  755. .tx_empty = ip22zilog_tx_empty,
  756. .set_mctrl = ip22zilog_set_mctrl,
  757. .get_mctrl = ip22zilog_get_mctrl,
  758. .stop_tx = ip22zilog_stop_tx,
  759. .start_tx = ip22zilog_start_tx,
  760. .stop_rx = ip22zilog_stop_rx,
  761. .enable_ms = ip22zilog_enable_ms,
  762. .break_ctl = ip22zilog_break_ctl,
  763. .startup = ip22zilog_startup,
  764. .shutdown = ip22zilog_shutdown,
  765. .set_termios = ip22zilog_set_termios,
  766. .type = ip22zilog_type,
  767. .release_port = ip22zilog_release_port,
  768. .request_port = ip22zilog_request_port,
  769. .config_port = ip22zilog_config_port,
  770. .verify_port = ip22zilog_verify_port,
  771. };
  772. static struct uart_ip22zilog_port *ip22zilog_port_table;
  773. static struct zilog_layout **ip22zilog_chip_regs;
  774. static struct uart_ip22zilog_port *ip22zilog_irq_chain;
  775. static int zilog_irq = -1;
  776. static void * __init alloc_one_table(unsigned long size)
  777. {
  778. return kzalloc(size, GFP_KERNEL);
  779. }
  780. static void __init ip22zilog_alloc_tables(void)
  781. {
  782. ip22zilog_port_table = (struct uart_ip22zilog_port *)
  783. alloc_one_table(NUM_CHANNELS * sizeof(struct uart_ip22zilog_port));
  784. ip22zilog_chip_regs = (struct zilog_layout **)
  785. alloc_one_table(NUM_IP22ZILOG * sizeof(struct zilog_layout *));
  786. if (ip22zilog_port_table == NULL || ip22zilog_chip_regs == NULL) {
  787. panic("IP22-Zilog: Cannot allocate IP22-Zilog tables.");
  788. }
  789. }
  790. /* Get the address of the registers for IP22-Zilog instance CHIP. */
  791. static struct zilog_layout * __init get_zs(int chip)
  792. {
  793. unsigned long base;
  794. if (chip < 0 || chip >= NUM_IP22ZILOG) {
  795. panic("IP22-Zilog: Illegal chip number %d in get_zs.", chip);
  796. }
  797. /* Not probe-able, hard code it. */
  798. base = (unsigned long) &sgioc->uart;
  799. zilog_irq = SGI_SERIAL_IRQ;
  800. request_mem_region(base, 8, "IP22-Zilog");
  801. return (struct zilog_layout *) base;
  802. }
  803. #define ZS_PUT_CHAR_MAX_DELAY 2000 /* 10 ms */
  804. #ifdef CONFIG_SERIAL_IP22_ZILOG_CONSOLE
  805. static void ip22zilog_put_char(struct uart_port *port, int ch)
  806. {
  807. struct zilog_channel *channel = ZILOG_CHANNEL_FROM_PORT(port);
  808. int loops = ZS_PUT_CHAR_MAX_DELAY;
  809. /* This is a timed polling loop so do not switch the explicit
  810. * udelay with ZSDELAY as that is a NOP on some platforms. -DaveM
  811. */
  812. do {
  813. unsigned char val = readb(&channel->control);
  814. if (val & Tx_BUF_EMP) {
  815. ZSDELAY();
  816. break;
  817. }
  818. udelay(5);
  819. } while (--loops);
  820. writeb(ch, &channel->data);
  821. ZSDELAY();
  822. ZS_WSYNC(channel);
  823. }
  824. static void
  825. ip22zilog_console_write(struct console *con, const char *s, unsigned int count)
  826. {
  827. struct uart_ip22zilog_port *up = &ip22zilog_port_table[con->index];
  828. unsigned long flags;
  829. spin_lock_irqsave(&up->port.lock, flags);
  830. uart_console_write(&up->port, s, count, ip22zilog_put_char);
  831. udelay(2);
  832. spin_unlock_irqrestore(&up->port.lock, flags);
  833. }
  834. static int __init ip22zilog_console_setup(struct console *con, char *options)
  835. {
  836. struct uart_ip22zilog_port *up = &ip22zilog_port_table[con->index];
  837. unsigned long flags;
  838. int baud = 9600, bits = 8;
  839. int parity = 'n';
  840. int flow = 'n';
  841. up->flags |= IP22ZILOG_FLAG_IS_CONS;
  842. printk(KERN_INFO "Console: ttyS%d (IP22-Zilog)\n", con->index);
  843. spin_lock_irqsave(&up->port.lock, flags);
  844. up->curregs[R15] |= BRKIE;
  845. __ip22zilog_startup(up);
  846. spin_unlock_irqrestore(&up->port.lock, flags);
  847. if (options)
  848. uart_parse_options(options, &baud, &parity, &bits, &flow);
  849. return uart_set_options(&up->port, con, baud, parity, bits, flow);
  850. }
  851. static struct uart_driver ip22zilog_reg;
  852. static struct console ip22zilog_console = {
  853. .name = "ttyS",
  854. .write = ip22zilog_console_write,
  855. .device = uart_console_device,
  856. .setup = ip22zilog_console_setup,
  857. .flags = CON_PRINTBUFFER,
  858. .index = -1,
  859. .data = &ip22zilog_reg,
  860. };
  861. #endif /* CONFIG_SERIAL_IP22_ZILOG_CONSOLE */
  862. static struct uart_driver ip22zilog_reg = {
  863. .owner = THIS_MODULE,
  864. .driver_name = "serial",
  865. .dev_name = "ttyS",
  866. .major = TTY_MAJOR,
  867. .minor = 64,
  868. .nr = NUM_CHANNELS,
  869. #ifdef CONFIG_SERIAL_IP22_ZILOG_CONSOLE
  870. .cons = &ip22zilog_console,
  871. #endif
  872. };
  873. static void __init ip22zilog_prepare(void)
  874. {
  875. struct uart_ip22zilog_port *up;
  876. struct zilog_layout *rp;
  877. int channel, chip;
  878. /*
  879. * Temporary fix.
  880. */
  881. for (channel = 0; channel < NUM_CHANNELS; channel++)
  882. spin_lock_init(&ip22zilog_port_table[channel].port.lock);
  883. ip22zilog_irq_chain = &ip22zilog_port_table[NUM_CHANNELS - 1];
  884. up = &ip22zilog_port_table[0];
  885. for (channel = NUM_CHANNELS - 1 ; channel > 0; channel--)
  886. up[channel].next = &up[channel - 1];
  887. up[channel].next = NULL;
  888. for (chip = 0; chip < NUM_IP22ZILOG; chip++) {
  889. if (!ip22zilog_chip_regs[chip]) {
  890. ip22zilog_chip_regs[chip] = rp = get_zs(chip);
  891. up[(chip * 2) + 0].port.membase = (char *) &rp->channelB;
  892. up[(chip * 2) + 1].port.membase = (char *) &rp->channelA;
  893. /* In theory mapbase is the physical address ... */
  894. up[(chip * 2) + 0].port.mapbase =
  895. (unsigned long) ioremap((unsigned long) &rp->channelB, 8);
  896. up[(chip * 2) + 1].port.mapbase =
  897. (unsigned long) ioremap((unsigned long) &rp->channelA, 8);
  898. }
  899. /* Channel A */
  900. up[(chip * 2) + 0].port.iotype = UPIO_MEM;
  901. up[(chip * 2) + 0].port.irq = zilog_irq;
  902. up[(chip * 2) + 0].port.uartclk = ZS_CLOCK;
  903. up[(chip * 2) + 0].port.fifosize = 1;
  904. up[(chip * 2) + 0].port.ops = &ip22zilog_pops;
  905. up[(chip * 2) + 0].port.type = PORT_IP22ZILOG;
  906. up[(chip * 2) + 0].port.flags = 0;
  907. up[(chip * 2) + 0].port.line = (chip * 2) + 0;
  908. up[(chip * 2) + 0].flags = 0;
  909. /* Channel B */
  910. up[(chip * 2) + 1].port.iotype = UPIO_MEM;
  911. up[(chip * 2) + 1].port.irq = zilog_irq;
  912. up[(chip * 2) + 1].port.uartclk = ZS_CLOCK;
  913. up[(chip * 2) + 1].port.fifosize = 1;
  914. up[(chip * 2) + 1].port.ops = &ip22zilog_pops;
  915. up[(chip * 2) + 1].port.type = PORT_IP22ZILOG;
  916. up[(chip * 2) + 1].port.line = (chip * 2) + 1;
  917. up[(chip * 2) + 1].flags |= IP22ZILOG_FLAG_IS_CHANNEL_A;
  918. }
  919. for (channel = 0; channel < NUM_CHANNELS; channel++) {
  920. struct uart_ip22zilog_port *up = &ip22zilog_port_table[channel];
  921. int brg;
  922. /* Normal serial TTY. */
  923. up->parity_mask = 0xff;
  924. up->curregs[R1] = EXT_INT_ENAB | INT_ALL_Rx | TxINT_ENAB;
  925. up->curregs[R4] = PAR_EVEN | X16CLK | SB1;
  926. up->curregs[R3] = RxENAB | Rx8;
  927. up->curregs[R5] = TxENAB | Tx8;
  928. up->curregs[R9] = NV | MIE;
  929. up->curregs[R10] = NRZ;
  930. up->curregs[R11] = TCBR | RCBR;
  931. brg = BPS_TO_BRG(9600, ZS_CLOCK / ZS_CLOCK_DIVISOR);
  932. up->curregs[R12] = (brg & 0xff);
  933. up->curregs[R13] = (brg >> 8) & 0xff;
  934. up->curregs[R14] = BRENAB;
  935. }
  936. }
  937. static int __init ip22zilog_ports_init(void)
  938. {
  939. int ret;
  940. printk(KERN_INFO "Serial: IP22 Zilog driver (%d chips).\n", NUM_IP22ZILOG);
  941. ip22zilog_prepare();
  942. if (request_irq(zilog_irq, ip22zilog_interrupt, 0,
  943. "IP22-Zilog", ip22zilog_irq_chain)) {
  944. panic("IP22-Zilog: Unable to register zs interrupt handler.\n");
  945. }
  946. ret = uart_register_driver(&ip22zilog_reg);
  947. if (ret == 0) {
  948. int i;
  949. for (i = 0; i < NUM_CHANNELS; i++) {
  950. struct uart_ip22zilog_port *up = &ip22zilog_port_table[i];
  951. uart_add_one_port(&ip22zilog_reg, &up->port);
  952. }
  953. }
  954. return ret;
  955. }
  956. static int __init ip22zilog_init(void)
  957. {
  958. /* IP22 Zilog setup is hard coded, no probing to do. */
  959. ip22zilog_alloc_tables();
  960. ip22zilog_ports_init();
  961. return 0;
  962. }
  963. static void __exit ip22zilog_exit(void)
  964. {
  965. int i;
  966. struct uart_ip22zilog_port *up;
  967. for (i = 0; i < NUM_CHANNELS; i++) {
  968. up = &ip22zilog_port_table[i];
  969. uart_remove_one_port(&ip22zilog_reg, &up->port);
  970. }
  971. /* Free IO mem */
  972. up = &ip22zilog_port_table[0];
  973. for (i = 0; i < NUM_IP22ZILOG; i++) {
  974. if (up[(i * 2) + 0].port.mapbase) {
  975. iounmap((void*)up[(i * 2) + 0].port.mapbase);
  976. up[(i * 2) + 0].port.mapbase = 0;
  977. }
  978. if (up[(i * 2) + 1].port.mapbase) {
  979. iounmap((void*)up[(i * 2) + 1].port.mapbase);
  980. up[(i * 2) + 1].port.mapbase = 0;
  981. }
  982. }
  983. uart_unregister_driver(&ip22zilog_reg);
  984. }
  985. module_init(ip22zilog_init);
  986. module_exit(ip22zilog_exit);
  987. /* David wrote it but I'm to blame for the bugs ... */
  988. MODULE_AUTHOR("Ralf Baechle <ralf@linux-mips.org>");
  989. MODULE_DESCRIPTION("SGI Zilog serial port driver");
  990. MODULE_LICENSE("GPL");