interface.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. /*
  2. * interface to user space for the gigaset driver
  3. *
  4. * Copyright (c) 2004 by Hansjoerg Lipp <hjlipp@web.de>
  5. *
  6. * =====================================================================
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. * =====================================================================
  12. */
  13. #include "gigaset.h"
  14. #include <linux/gigaset_dev.h>
  15. #include <linux/tty.h>
  16. #include <linux/tty_flip.h>
  17. /*** our ioctls ***/
  18. static int if_lock(struct cardstate *cs, int *arg)
  19. {
  20. int cmd = *arg;
  21. dbg(DEBUG_IF, "%u: if_lock (%d)", cs->minor_index, cmd);
  22. if (cmd > 1)
  23. return -EINVAL;
  24. if (cmd < 0) {
  25. *arg = atomic_read(&cs->mstate) == MS_LOCKED; //FIXME remove?
  26. return 0;
  27. }
  28. if (!cmd && atomic_read(&cs->mstate) == MS_LOCKED
  29. && atomic_read(&cs->connected)) {
  30. cs->ops->set_modem_ctrl(cs, 0, TIOCM_DTR|TIOCM_RTS);
  31. cs->ops->baud_rate(cs, B115200);
  32. cs->ops->set_line_ctrl(cs, CS8);
  33. cs->control_state = TIOCM_DTR|TIOCM_RTS;
  34. }
  35. cs->waiting = 1;
  36. if (!gigaset_add_event(cs, &cs->at_state, EV_IF_LOCK,
  37. NULL, cmd, NULL)) {
  38. cs->waiting = 0;
  39. return -ENOMEM;
  40. }
  41. dbg(DEBUG_CMD, "scheduling IF_LOCK");
  42. gigaset_schedule_event(cs);
  43. wait_event(cs->waitqueue, !cs->waiting);
  44. if (cs->cmd_result >= 0) {
  45. *arg = cs->cmd_result;
  46. return 0;
  47. }
  48. return cs->cmd_result;
  49. }
  50. static int if_version(struct cardstate *cs, unsigned arg[4])
  51. {
  52. static const unsigned version[4] = GIG_VERSION;
  53. static const unsigned compat[4] = GIG_COMPAT;
  54. unsigned cmd = arg[0];
  55. dbg(DEBUG_IF, "%u: if_version (%d)", cs->minor_index, cmd);
  56. switch (cmd) {
  57. case GIGVER_DRIVER:
  58. memcpy(arg, version, sizeof version);
  59. return 0;
  60. case GIGVER_COMPAT:
  61. memcpy(arg, compat, sizeof compat);
  62. return 0;
  63. case GIGVER_FWBASE:
  64. cs->waiting = 1;
  65. if (!gigaset_add_event(cs, &cs->at_state, EV_IF_VER,
  66. NULL, 0, arg)) {
  67. cs->waiting = 0;
  68. return -ENOMEM;
  69. }
  70. dbg(DEBUG_CMD, "scheduling IF_VER");
  71. gigaset_schedule_event(cs);
  72. wait_event(cs->waitqueue, !cs->waiting);
  73. if (cs->cmd_result >= 0)
  74. return 0;
  75. return cs->cmd_result;
  76. default:
  77. return -EINVAL;
  78. }
  79. }
  80. static int if_config(struct cardstate *cs, int *arg)
  81. {
  82. dbg(DEBUG_IF, "%u: if_config (%d)", cs->minor_index, *arg);
  83. if (*arg != 1)
  84. return -EINVAL;
  85. if (atomic_read(&cs->mstate) != MS_LOCKED)
  86. return -EBUSY;
  87. *arg = 0;
  88. return gigaset_enterconfigmode(cs);
  89. }
  90. /*** the terminal driver ***/
  91. /* stolen from usbserial and some other tty drivers */
  92. static int if_open(struct tty_struct *tty, struct file *filp);
  93. static void if_close(struct tty_struct *tty, struct file *filp);
  94. static int if_ioctl(struct tty_struct *tty, struct file *file,
  95. unsigned int cmd, unsigned long arg);
  96. static int if_write_room(struct tty_struct *tty);
  97. static int if_chars_in_buffer(struct tty_struct *tty);
  98. static void if_throttle(struct tty_struct *tty);
  99. static void if_unthrottle(struct tty_struct *tty);
  100. static void if_set_termios(struct tty_struct *tty, struct termios *old);
  101. static int if_tiocmget(struct tty_struct *tty, struct file *file);
  102. static int if_tiocmset(struct tty_struct *tty, struct file *file,
  103. unsigned int set, unsigned int clear);
  104. static int if_write(struct tty_struct *tty,
  105. const unsigned char *buf, int count);
  106. static struct tty_operations if_ops = {
  107. .open = if_open,
  108. .close = if_close,
  109. .ioctl = if_ioctl,
  110. .write = if_write,
  111. .write_room = if_write_room,
  112. .chars_in_buffer = if_chars_in_buffer,
  113. .set_termios = if_set_termios,
  114. .throttle = if_throttle,
  115. .unthrottle = if_unthrottle,
  116. #if 0
  117. .break_ctl = serial_break,
  118. #endif
  119. .tiocmget = if_tiocmget,
  120. .tiocmset = if_tiocmset,
  121. };
  122. static int if_open(struct tty_struct *tty, struct file *filp)
  123. {
  124. struct cardstate *cs;
  125. unsigned long flags;
  126. dbg(DEBUG_IF, "%d+%d: %s()", tty->driver->minor_start, tty->index,
  127. __FUNCTION__);
  128. tty->driver_data = NULL;
  129. cs = gigaset_get_cs_by_tty(tty);
  130. if (!cs)
  131. return -ENODEV;
  132. if (down_interruptible(&cs->sem))
  133. return -ERESTARTSYS; // FIXME -EINTR?
  134. tty->driver_data = cs;
  135. ++cs->open_count;
  136. if (cs->open_count == 1) {
  137. spin_lock_irqsave(&cs->lock, flags);
  138. cs->tty = tty;
  139. spin_unlock_irqrestore(&cs->lock, flags);
  140. tty->low_latency = 1; //FIXME test
  141. }
  142. up(&cs->sem);
  143. return 0;
  144. }
  145. static void if_close(struct tty_struct *tty, struct file *filp)
  146. {
  147. struct cardstate *cs;
  148. unsigned long flags;
  149. cs = (struct cardstate *) tty->driver_data;
  150. if (!cs) {
  151. err("cs==NULL in %s", __FUNCTION__);
  152. return;
  153. }
  154. dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __FUNCTION__);
  155. down(&cs->sem);
  156. if (!cs->open_count)
  157. warn("%s: device not opened", __FUNCTION__);
  158. else {
  159. if (!--cs->open_count) {
  160. spin_lock_irqsave(&cs->lock, flags);
  161. cs->tty = NULL;
  162. spin_unlock_irqrestore(&cs->lock, flags);
  163. }
  164. }
  165. up(&cs->sem);
  166. }
  167. static int if_ioctl(struct tty_struct *tty, struct file *file,
  168. unsigned int cmd, unsigned long arg)
  169. {
  170. struct cardstate *cs;
  171. int retval = -ENODEV;
  172. int int_arg;
  173. unsigned char buf[6];
  174. unsigned version[4];
  175. cs = (struct cardstate *) tty->driver_data;
  176. if (!cs) {
  177. err("cs==NULL in %s", __FUNCTION__);
  178. return -ENODEV;
  179. }
  180. dbg(DEBUG_IF, "%u: %s(0x%x)", cs->minor_index, __FUNCTION__, cmd);
  181. if (down_interruptible(&cs->sem))
  182. return -ERESTARTSYS; // FIXME -EINTR?
  183. if (!cs->open_count)
  184. warn("%s: device not opened", __FUNCTION__);
  185. else {
  186. retval = 0;
  187. switch (cmd) {
  188. case GIGASET_REDIR:
  189. retval = get_user(int_arg, (int __user *) arg);
  190. if (retval >= 0)
  191. retval = if_lock(cs, &int_arg);
  192. if (retval >= 0)
  193. retval = put_user(int_arg, (int __user *) arg);
  194. break;
  195. case GIGASET_CONFIG:
  196. retval = get_user(int_arg, (int __user *) arg);
  197. if (retval >= 0)
  198. retval = if_config(cs, &int_arg);
  199. if (retval >= 0)
  200. retval = put_user(int_arg, (int __user *) arg);
  201. break;
  202. case GIGASET_BRKCHARS:
  203. //FIXME test if MS_LOCKED
  204. gigaset_dbg_buffer(DEBUG_IF, "GIGASET_BRKCHARS",
  205. 6, (const unsigned char *) arg, 1);
  206. if (!atomic_read(&cs->connected)) {
  207. dbg(DEBUG_ANY,
  208. "can't communicate with unplugged device");
  209. retval = -ENODEV;
  210. break;
  211. }
  212. retval = copy_from_user(&buf,
  213. (const unsigned char __user *) arg, 6)
  214. ? -EFAULT : 0;
  215. if (retval >= 0)
  216. retval = cs->ops->brkchars(cs, buf);
  217. break;
  218. case GIGASET_VERSION:
  219. retval = copy_from_user(version,
  220. (unsigned __user *) arg,
  221. sizeof version) ? -EFAULT : 0;
  222. if (retval >= 0)
  223. retval = if_version(cs, version);
  224. if (retval >= 0)
  225. retval = copy_to_user((unsigned __user *) arg,
  226. version, sizeof version)
  227. ? -EFAULT : 0;
  228. break;
  229. default:
  230. dbg(DEBUG_ANY, "%s: arg not supported - 0x%04x",
  231. __FUNCTION__, cmd);
  232. retval = -ENOIOCTLCMD;
  233. }
  234. }
  235. up(&cs->sem);
  236. return retval;
  237. }
  238. static int if_tiocmget(struct tty_struct *tty, struct file *file)
  239. {
  240. struct cardstate *cs;
  241. int retval;
  242. cs = (struct cardstate *) tty->driver_data;
  243. if (!cs) {
  244. err("cs==NULL in %s", __FUNCTION__);
  245. return -ENODEV;
  246. }
  247. dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __FUNCTION__);
  248. if (down_interruptible(&cs->sem))
  249. return -ERESTARTSYS; // FIXME -EINTR?
  250. // FIXME read from device?
  251. retval = cs->control_state & (TIOCM_RTS|TIOCM_DTR);
  252. up(&cs->sem);
  253. return retval;
  254. }
  255. static int if_tiocmset(struct tty_struct *tty, struct file *file,
  256. unsigned int set, unsigned int clear)
  257. {
  258. struct cardstate *cs;
  259. int retval;
  260. unsigned mc;
  261. cs = (struct cardstate *) tty->driver_data;
  262. if (!cs) {
  263. err("cs==NULL in %s", __FUNCTION__);
  264. return -ENODEV;
  265. }
  266. dbg(DEBUG_IF,
  267. "%u: %s(0x%x, 0x%x)", cs->minor_index, __FUNCTION__, set, clear);
  268. if (down_interruptible(&cs->sem))
  269. return -ERESTARTSYS; // FIXME -EINTR?
  270. if (!atomic_read(&cs->connected)) {
  271. dbg(DEBUG_ANY, "can't communicate with unplugged device");
  272. retval = -ENODEV;
  273. } else {
  274. mc = (cs->control_state | set) & ~clear & (TIOCM_RTS|TIOCM_DTR);
  275. retval = cs->ops->set_modem_ctrl(cs, cs->control_state, mc);
  276. cs->control_state = mc;
  277. }
  278. up(&cs->sem);
  279. return retval;
  280. }
  281. static int if_write(struct tty_struct *tty, const unsigned char *buf, int count)
  282. {
  283. struct cardstate *cs;
  284. int retval = -ENODEV;
  285. cs = (struct cardstate *) tty->driver_data;
  286. if (!cs) {
  287. err("cs==NULL in %s", __FUNCTION__);
  288. return -ENODEV;
  289. }
  290. dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __FUNCTION__);
  291. if (down_interruptible(&cs->sem))
  292. return -ERESTARTSYS; // FIXME -EINTR?
  293. if (!cs->open_count)
  294. warn("%s: device not opened", __FUNCTION__);
  295. else if (atomic_read(&cs->mstate) != MS_LOCKED) {
  296. warn("can't write to unlocked device");
  297. retval = -EBUSY;
  298. } else if (!atomic_read(&cs->connected)) {
  299. dbg(DEBUG_ANY, "can't write to unplugged device");
  300. retval = -EBUSY; //FIXME
  301. } else {
  302. retval = cs->ops->write_cmd(cs, buf, count,
  303. &cs->if_wake_tasklet);
  304. }
  305. up(&cs->sem);
  306. return retval;
  307. }
  308. static int if_write_room(struct tty_struct *tty)
  309. {
  310. struct cardstate *cs;
  311. int retval = -ENODEV;
  312. cs = (struct cardstate *) tty->driver_data;
  313. if (!cs) {
  314. err("cs==NULL in %s", __FUNCTION__);
  315. return -ENODEV;
  316. }
  317. dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __FUNCTION__);
  318. if (down_interruptible(&cs->sem))
  319. return -ERESTARTSYS; // FIXME -EINTR?
  320. if (!cs->open_count)
  321. warn("%s: device not opened", __FUNCTION__);
  322. else if (atomic_read(&cs->mstate) != MS_LOCKED) {
  323. warn("can't write to unlocked device");
  324. retval = -EBUSY; //FIXME
  325. } else if (!atomic_read(&cs->connected)) {
  326. dbg(DEBUG_ANY, "can't write to unplugged device");
  327. retval = -EBUSY; //FIXME
  328. } else
  329. retval = cs->ops->write_room(cs);
  330. up(&cs->sem);
  331. return retval;
  332. }
  333. static int if_chars_in_buffer(struct tty_struct *tty)
  334. {
  335. struct cardstate *cs;
  336. int retval = -ENODEV;
  337. cs = (struct cardstate *) tty->driver_data;
  338. if (!cs) {
  339. err("cs==NULL in %s", __FUNCTION__);
  340. return -ENODEV;
  341. }
  342. dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __FUNCTION__);
  343. if (down_interruptible(&cs->sem))
  344. return -ERESTARTSYS; // FIXME -EINTR?
  345. if (!cs->open_count)
  346. warn("%s: device not opened", __FUNCTION__);
  347. else if (atomic_read(&cs->mstate) != MS_LOCKED) {
  348. warn("can't write to unlocked device");
  349. retval = -EBUSY;
  350. } else if (!atomic_read(&cs->connected)) {
  351. dbg(DEBUG_ANY, "can't write to unplugged device");
  352. retval = -EBUSY; //FIXME
  353. } else
  354. retval = cs->ops->chars_in_buffer(cs);
  355. up(&cs->sem);
  356. return retval;
  357. }
  358. static void if_throttle(struct tty_struct *tty)
  359. {
  360. struct cardstate *cs;
  361. cs = (struct cardstate *) tty->driver_data;
  362. if (!cs) {
  363. err("cs==NULL in %s", __FUNCTION__);
  364. return;
  365. }
  366. dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __FUNCTION__);
  367. down(&cs->sem);
  368. if (!cs->open_count)
  369. warn("%s: device not opened", __FUNCTION__);
  370. else {
  371. //FIXME
  372. }
  373. up(&cs->sem);
  374. }
  375. static void if_unthrottle(struct tty_struct *tty)
  376. {
  377. struct cardstate *cs;
  378. cs = (struct cardstate *) tty->driver_data;
  379. if (!cs) {
  380. err("cs==NULL in %s", __FUNCTION__);
  381. return;
  382. }
  383. dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __FUNCTION__);
  384. down(&cs->sem);
  385. if (!cs->open_count)
  386. warn("%s: device not opened", __FUNCTION__);
  387. else {
  388. //FIXME
  389. }
  390. up(&cs->sem);
  391. }
  392. static void if_set_termios(struct tty_struct *tty, struct termios *old)
  393. {
  394. struct cardstate *cs;
  395. unsigned int iflag;
  396. unsigned int cflag;
  397. unsigned int old_cflag;
  398. unsigned int control_state, new_state;
  399. cs = (struct cardstate *) tty->driver_data;
  400. if (!cs) {
  401. err("cs==NULL in %s", __FUNCTION__);
  402. return;
  403. }
  404. dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __FUNCTION__);
  405. down(&cs->sem);
  406. if (!cs->open_count) {
  407. warn("%s: device not opened", __FUNCTION__);
  408. goto out;
  409. }
  410. if (!atomic_read(&cs->connected)) {
  411. dbg(DEBUG_ANY, "can't communicate with unplugged device");
  412. goto out;
  413. }
  414. // stolen from mct_u232.c
  415. iflag = tty->termios->c_iflag;
  416. cflag = tty->termios->c_cflag;
  417. old_cflag = old ? old->c_cflag : cflag; //FIXME?
  418. dbg(DEBUG_IF, "%u: iflag %x cflag %x old %x", cs->minor_index,
  419. iflag, cflag, old_cflag);
  420. /* get a local copy of the current port settings */
  421. control_state = cs->control_state;
  422. /*
  423. * Update baud rate.
  424. * Do not attempt to cache old rates and skip settings,
  425. * disconnects screw such tricks up completely.
  426. * Premature optimization is the root of all evil.
  427. */
  428. /* reassert DTR and (maybe) RTS on transition from B0 */
  429. if ((old_cflag & CBAUD) == B0) {
  430. new_state = control_state | TIOCM_DTR;
  431. /* don't set RTS if using hardware flow control */
  432. if (!(old_cflag & CRTSCTS))
  433. new_state |= TIOCM_RTS;
  434. dbg(DEBUG_IF, "%u: from B0 - set DTR%s", cs->minor_index,
  435. (new_state & TIOCM_RTS) ? " only" : "/RTS");
  436. cs->ops->set_modem_ctrl(cs, control_state, new_state);
  437. control_state = new_state;
  438. }
  439. cs->ops->baud_rate(cs, cflag & CBAUD);
  440. if ((cflag & CBAUD) == B0) {
  441. /* Drop RTS and DTR */
  442. dbg(DEBUG_IF, "%u: to B0 - drop DTR/RTS", cs->minor_index);
  443. new_state = control_state & ~(TIOCM_DTR | TIOCM_RTS);
  444. cs->ops->set_modem_ctrl(cs, control_state, new_state);
  445. control_state = new_state;
  446. }
  447. /*
  448. * Update line control register (LCR)
  449. */
  450. cs->ops->set_line_ctrl(cs, cflag);
  451. #if 0
  452. //FIXME this hangs M101 [ts 2005-03-09]
  453. //FIXME do we need this?
  454. /*
  455. * Set flow control: well, I do not really now how to handle DTR/RTS.
  456. * Just do what we have seen with SniffUSB on Win98.
  457. */
  458. /* Drop DTR/RTS if no flow control otherwise assert */
  459. dbg(DEBUG_IF, "%u: control_state %x", cs->minor_index, control_state);
  460. new_state = control_state;
  461. if ((iflag & IXOFF) || (iflag & IXON) || (cflag & CRTSCTS))
  462. new_state |= TIOCM_DTR | TIOCM_RTS;
  463. else
  464. new_state &= ~(TIOCM_DTR | TIOCM_RTS);
  465. if (new_state != control_state) {
  466. dbg(DEBUG_IF, "%u: new_state %x", cs->minor_index, new_state);
  467. gigaset_set_modem_ctrl(cs, control_state, new_state);
  468. control_state = new_state;
  469. }
  470. #endif
  471. /* save off the modified port settings */
  472. cs->control_state = control_state;
  473. out:
  474. up(&cs->sem);
  475. }
  476. /* wakeup tasklet for the write operation */
  477. static void if_wake(unsigned long data)
  478. {
  479. struct cardstate *cs = (struct cardstate *) data;
  480. struct tty_struct *tty;
  481. tty = cs->tty;
  482. if (!tty)
  483. return;
  484. if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
  485. tty->ldisc.write_wakeup) {
  486. dbg(DEBUG_IF, "write wakeup call");
  487. tty->ldisc.write_wakeup(tty);
  488. }
  489. wake_up_interruptible(&tty->write_wait);
  490. }
  491. /*** interface to common ***/
  492. void gigaset_if_init(struct cardstate *cs)
  493. {
  494. struct gigaset_driver *drv;
  495. drv = cs->driver;
  496. if (!drv->have_tty)
  497. return;
  498. tasklet_init(&cs->if_wake_tasklet, &if_wake, (unsigned long) cs);
  499. tty_register_device(drv->tty, cs->minor_index, NULL);
  500. }
  501. void gigaset_if_free(struct cardstate *cs)
  502. {
  503. struct gigaset_driver *drv;
  504. drv = cs->driver;
  505. if (!drv->have_tty)
  506. return;
  507. tasklet_disable(&cs->if_wake_tasklet);
  508. tasklet_kill(&cs->if_wake_tasklet);
  509. tty_unregister_device(drv->tty, cs->minor_index);
  510. }
  511. void gigaset_if_receive(struct cardstate *cs,
  512. unsigned char *buffer, size_t len)
  513. {
  514. unsigned long flags;
  515. struct tty_struct *tty;
  516. spin_lock_irqsave(&cs->lock, flags);
  517. if ((tty = cs->tty) == NULL)
  518. dbg(DEBUG_ANY, "receive on closed device");
  519. else {
  520. tty_buffer_request_room(tty, len);
  521. tty_insert_flip_string(tty, buffer, len);
  522. tty_flip_buffer_push(tty);
  523. }
  524. spin_unlock_irqrestore(&cs->lock, flags);
  525. }
  526. EXPORT_SYMBOL_GPL(gigaset_if_receive);
  527. /* gigaset_if_initdriver
  528. * Initialize tty interface.
  529. * parameters:
  530. * drv Driver
  531. * procname Name of the driver (e.g. for /proc/tty/drivers)
  532. * devname Name of the device files (prefix without minor number)
  533. * devfsname Devfs name of the device files without %d
  534. */
  535. void gigaset_if_initdriver(struct gigaset_driver *drv, const char *procname,
  536. const char *devname, const char *devfsname)
  537. {
  538. unsigned minors = drv->minors;
  539. int ret;
  540. struct tty_driver *tty;
  541. drv->have_tty = 0;
  542. if ((drv->tty = alloc_tty_driver(minors)) == NULL)
  543. goto enomem;
  544. tty = drv->tty;
  545. tty->magic = TTY_DRIVER_MAGIC,
  546. tty->major = GIG_MAJOR,
  547. tty->type = TTY_DRIVER_TYPE_SERIAL,
  548. tty->subtype = SERIAL_TYPE_NORMAL,
  549. tty->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_NO_DEVFS,
  550. tty->driver_name = procname;
  551. tty->name = devname;
  552. tty->minor_start = drv->minor;
  553. tty->num = drv->minors;
  554. tty->owner = THIS_MODULE;
  555. tty->devfs_name = devfsname;
  556. tty->init_termios = tty_std_termios; //FIXME
  557. tty->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; //FIXME
  558. tty_set_operations(tty, &if_ops);
  559. ret = tty_register_driver(tty);
  560. if (ret < 0) {
  561. warn("failed to register tty driver (error %d)", ret);
  562. goto error;
  563. }
  564. dbg(DEBUG_IF, "tty driver initialized");
  565. drv->have_tty = 1;
  566. return;
  567. enomem:
  568. warn("could not allocate tty structures");
  569. error:
  570. if (drv->tty)
  571. put_tty_driver(drv->tty);
  572. }
  573. void gigaset_if_freedriver(struct gigaset_driver *drv)
  574. {
  575. if (!drv->have_tty)
  576. return;
  577. drv->have_tty = 0;
  578. tty_unregister_driver(drv->tty);
  579. put_tty_driver(drv->tty);
  580. }