interface.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  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. gig_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. gig_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. gig_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. gig_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. gig_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. gig_dbg(DEBUG_IF, "%d+%d: %s()",
  127. tty->driver->minor_start, tty->index, __func__);
  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", __func__);
  152. return;
  153. }
  154. gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
  155. down(&cs->sem);
  156. if (!cs->open_count)
  157. warn("%s: device not opened", __func__);
  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", __func__);
  178. return -ENODEV;
  179. }
  180. gig_dbg(DEBUG_IF, "%u: %s(0x%x)", cs->minor_index, __func__, cmd);
  181. if (down_interruptible(&cs->sem))
  182. return -ERESTARTSYS; // FIXME -EINTR?
  183. if (!cs->open_count)
  184. warn("%s: device not opened", __func__);
  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. if (!atomic_read(&cs->connected)) {
  205. gig_dbg(DEBUG_ANY,
  206. "can't communicate with unplugged device");
  207. retval = -ENODEV;
  208. break;
  209. }
  210. retval = copy_from_user(&buf,
  211. (const unsigned char __user *) arg, 6)
  212. ? -EFAULT : 0;
  213. if (retval >= 0) {
  214. gigaset_dbg_buffer(DEBUG_IF, "GIGASET_BRKCHARS",
  215. 6, (const unsigned char *) arg);
  216. retval = cs->ops->brkchars(cs, buf);
  217. }
  218. break;
  219. case GIGASET_VERSION:
  220. retval = copy_from_user(version,
  221. (unsigned __user *) arg, sizeof version)
  222. ? -EFAULT : 0;
  223. if (retval >= 0)
  224. retval = if_version(cs, version);
  225. if (retval >= 0)
  226. retval = copy_to_user((unsigned __user *) arg,
  227. version, sizeof version)
  228. ? -EFAULT : 0;
  229. break;
  230. default:
  231. gig_dbg(DEBUG_ANY, "%s: arg not supported - 0x%04x",
  232. __func__, cmd);
  233. retval = -ENOIOCTLCMD;
  234. }
  235. }
  236. up(&cs->sem);
  237. return retval;
  238. }
  239. static int if_tiocmget(struct tty_struct *tty, struct file *file)
  240. {
  241. struct cardstate *cs;
  242. int retval;
  243. cs = (struct cardstate *) tty->driver_data;
  244. if (!cs) {
  245. err("cs==NULL in %s", __func__);
  246. return -ENODEV;
  247. }
  248. gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
  249. if (down_interruptible(&cs->sem))
  250. return -ERESTARTSYS; // FIXME -EINTR?
  251. // FIXME read from device?
  252. retval = cs->control_state & (TIOCM_RTS|TIOCM_DTR);
  253. up(&cs->sem);
  254. return retval;
  255. }
  256. static int if_tiocmset(struct tty_struct *tty, struct file *file,
  257. unsigned int set, unsigned int clear)
  258. {
  259. struct cardstate *cs;
  260. int retval;
  261. unsigned mc;
  262. cs = (struct cardstate *) tty->driver_data;
  263. if (!cs) {
  264. err("cs==NULL in %s", __func__);
  265. return -ENODEV;
  266. }
  267. gig_dbg(DEBUG_IF, "%u: %s(0x%x, 0x%x)",
  268. cs->minor_index, __func__, set, clear);
  269. if (down_interruptible(&cs->sem))
  270. return -ERESTARTSYS; // FIXME -EINTR?
  271. if (!atomic_read(&cs->connected)) {
  272. gig_dbg(DEBUG_ANY, "can't communicate with unplugged device");
  273. retval = -ENODEV;
  274. } else {
  275. mc = (cs->control_state | set) & ~clear & (TIOCM_RTS|TIOCM_DTR);
  276. retval = cs->ops->set_modem_ctrl(cs, cs->control_state, mc);
  277. cs->control_state = mc;
  278. }
  279. up(&cs->sem);
  280. return retval;
  281. }
  282. static int if_write(struct tty_struct *tty, const unsigned char *buf, int count)
  283. {
  284. struct cardstate *cs;
  285. int retval = -ENODEV;
  286. cs = (struct cardstate *) tty->driver_data;
  287. if (!cs) {
  288. err("cs==NULL in %s", __func__);
  289. return -ENODEV;
  290. }
  291. gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
  292. if (down_interruptible(&cs->sem))
  293. return -ERESTARTSYS; // FIXME -EINTR?
  294. if (!cs->open_count)
  295. warn("%s: device not opened", __func__);
  296. else if (atomic_read(&cs->mstate) != MS_LOCKED) {
  297. warn("can't write to unlocked device");
  298. retval = -EBUSY;
  299. } else if (!atomic_read(&cs->connected)) {
  300. gig_dbg(DEBUG_ANY, "can't write to unplugged device");
  301. retval = -EBUSY; //FIXME
  302. } else {
  303. retval = cs->ops->write_cmd(cs, buf, count,
  304. &cs->if_wake_tasklet);
  305. }
  306. up(&cs->sem);
  307. return retval;
  308. }
  309. static int if_write_room(struct tty_struct *tty)
  310. {
  311. struct cardstate *cs;
  312. int retval = -ENODEV;
  313. cs = (struct cardstate *) tty->driver_data;
  314. if (!cs) {
  315. err("cs==NULL in %s", __func__);
  316. return -ENODEV;
  317. }
  318. gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
  319. if (down_interruptible(&cs->sem))
  320. return -ERESTARTSYS; // FIXME -EINTR?
  321. if (!cs->open_count)
  322. warn("%s: device not opened", __func__);
  323. else if (atomic_read(&cs->mstate) != MS_LOCKED) {
  324. warn("can't write to unlocked device");
  325. retval = -EBUSY; //FIXME
  326. } else if (!atomic_read(&cs->connected)) {
  327. gig_dbg(DEBUG_ANY, "can't write to unplugged device");
  328. retval = -EBUSY; //FIXME
  329. } else
  330. retval = cs->ops->write_room(cs);
  331. up(&cs->sem);
  332. return retval;
  333. }
  334. static int if_chars_in_buffer(struct tty_struct *tty)
  335. {
  336. struct cardstate *cs;
  337. int retval = -ENODEV;
  338. cs = (struct cardstate *) tty->driver_data;
  339. if (!cs) {
  340. err("cs==NULL in %s", __func__);
  341. return -ENODEV;
  342. }
  343. gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
  344. if (down_interruptible(&cs->sem))
  345. return -ERESTARTSYS; // FIXME -EINTR?
  346. if (!cs->open_count)
  347. warn("%s: device not opened", __func__);
  348. else if (atomic_read(&cs->mstate) != MS_LOCKED) {
  349. warn("can't write to unlocked device");
  350. retval = -EBUSY;
  351. } else if (!atomic_read(&cs->connected)) {
  352. gig_dbg(DEBUG_ANY, "can't write to unplugged device");
  353. retval = -EBUSY; //FIXME
  354. } else
  355. retval = cs->ops->chars_in_buffer(cs);
  356. up(&cs->sem);
  357. return retval;
  358. }
  359. static void if_throttle(struct tty_struct *tty)
  360. {
  361. struct cardstate *cs;
  362. cs = (struct cardstate *) tty->driver_data;
  363. if (!cs) {
  364. err("cs==NULL in %s", __func__);
  365. return;
  366. }
  367. gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
  368. down(&cs->sem);
  369. if (!cs->open_count)
  370. warn("%s: device not opened", __func__);
  371. else {
  372. //FIXME
  373. }
  374. up(&cs->sem);
  375. }
  376. static void if_unthrottle(struct tty_struct *tty)
  377. {
  378. struct cardstate *cs;
  379. cs = (struct cardstate *) tty->driver_data;
  380. if (!cs) {
  381. err("cs==NULL in %s", __func__);
  382. return;
  383. }
  384. gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
  385. down(&cs->sem);
  386. if (!cs->open_count)
  387. warn("%s: device not opened", __func__);
  388. else {
  389. //FIXME
  390. }
  391. up(&cs->sem);
  392. }
  393. static void if_set_termios(struct tty_struct *tty, struct termios *old)
  394. {
  395. struct cardstate *cs;
  396. unsigned int iflag;
  397. unsigned int cflag;
  398. unsigned int old_cflag;
  399. unsigned int control_state, new_state;
  400. cs = (struct cardstate *) tty->driver_data;
  401. if (!cs) {
  402. err("cs==NULL in %s", __func__);
  403. return;
  404. }
  405. gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
  406. down(&cs->sem);
  407. if (!cs->open_count) {
  408. warn("%s: device not opened", __func__);
  409. goto out;
  410. }
  411. if (!atomic_read(&cs->connected)) {
  412. gig_dbg(DEBUG_ANY, "can't communicate with unplugged device");
  413. goto out;
  414. }
  415. // stolen from mct_u232.c
  416. iflag = tty->termios->c_iflag;
  417. cflag = tty->termios->c_cflag;
  418. old_cflag = old ? old->c_cflag : cflag; //FIXME?
  419. gig_dbg(DEBUG_IF, "%u: iflag %x cflag %x old %x",
  420. cs->minor_index, iflag, cflag, old_cflag);
  421. /* get a local copy of the current port settings */
  422. control_state = cs->control_state;
  423. /*
  424. * Update baud rate.
  425. * Do not attempt to cache old rates and skip settings,
  426. * disconnects screw such tricks up completely.
  427. * Premature optimization is the root of all evil.
  428. */
  429. /* reassert DTR and (maybe) RTS on transition from B0 */
  430. if ((old_cflag & CBAUD) == B0) {
  431. new_state = control_state | TIOCM_DTR;
  432. /* don't set RTS if using hardware flow control */
  433. if (!(old_cflag & CRTSCTS))
  434. new_state |= TIOCM_RTS;
  435. gig_dbg(DEBUG_IF, "%u: from B0 - set DTR%s",
  436. cs->minor_index,
  437. (new_state & TIOCM_RTS) ? " only" : "/RTS");
  438. cs->ops->set_modem_ctrl(cs, control_state, new_state);
  439. control_state = new_state;
  440. }
  441. cs->ops->baud_rate(cs, cflag & CBAUD);
  442. if ((cflag & CBAUD) == B0) {
  443. /* Drop RTS and DTR */
  444. gig_dbg(DEBUG_IF, "%u: to B0 - drop DTR/RTS", cs->minor_index);
  445. new_state = control_state & ~(TIOCM_DTR | TIOCM_RTS);
  446. cs->ops->set_modem_ctrl(cs, control_state, new_state);
  447. control_state = new_state;
  448. }
  449. /*
  450. * Update line control register (LCR)
  451. */
  452. cs->ops->set_line_ctrl(cs, cflag);
  453. #if 0
  454. //FIXME this hangs M101 [ts 2005-03-09]
  455. //FIXME do we need this?
  456. /*
  457. * Set flow control: well, I do not really now how to handle DTR/RTS.
  458. * Just do what we have seen with SniffUSB on Win98.
  459. */
  460. /* Drop DTR/RTS if no flow control otherwise assert */
  461. gig_dbg(DEBUG_IF, "%u: control_state %x",
  462. cs->minor_index, control_state);
  463. new_state = control_state;
  464. if ((iflag & IXOFF) || (iflag & IXON) || (cflag & CRTSCTS))
  465. new_state |= TIOCM_DTR | TIOCM_RTS;
  466. else
  467. new_state &= ~(TIOCM_DTR | TIOCM_RTS);
  468. if (new_state != control_state) {
  469. gig_dbg(DEBUG_IF, "%u: new_state %x",
  470. cs->minor_index, new_state);
  471. gigaset_set_modem_ctrl(cs, control_state, new_state);
  472. control_state = new_state;
  473. }
  474. #endif
  475. /* save off the modified port settings */
  476. cs->control_state = control_state;
  477. out:
  478. up(&cs->sem);
  479. }
  480. /* wakeup tasklet for the write operation */
  481. static void if_wake(unsigned long data)
  482. {
  483. struct cardstate *cs = (struct cardstate *) data;
  484. struct tty_struct *tty;
  485. tty = cs->tty;
  486. if (!tty)
  487. return;
  488. if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
  489. tty->ldisc.write_wakeup) {
  490. gig_dbg(DEBUG_IF, "write wakeup call");
  491. tty->ldisc.write_wakeup(tty);
  492. }
  493. wake_up_interruptible(&tty->write_wait);
  494. }
  495. /*** interface to common ***/
  496. void gigaset_if_init(struct cardstate *cs)
  497. {
  498. struct gigaset_driver *drv;
  499. drv = cs->driver;
  500. if (!drv->have_tty)
  501. return;
  502. tasklet_init(&cs->if_wake_tasklet, &if_wake, (unsigned long) cs);
  503. tty_register_device(drv->tty, cs->minor_index, NULL);
  504. }
  505. void gigaset_if_free(struct cardstate *cs)
  506. {
  507. struct gigaset_driver *drv;
  508. drv = cs->driver;
  509. if (!drv->have_tty)
  510. return;
  511. tasklet_disable(&cs->if_wake_tasklet);
  512. tasklet_kill(&cs->if_wake_tasklet);
  513. tty_unregister_device(drv->tty, cs->minor_index);
  514. }
  515. void gigaset_if_receive(struct cardstate *cs,
  516. unsigned char *buffer, size_t len)
  517. {
  518. unsigned long flags;
  519. struct tty_struct *tty;
  520. spin_lock_irqsave(&cs->lock, flags);
  521. if ((tty = cs->tty) == NULL)
  522. gig_dbg(DEBUG_ANY, "receive on closed device");
  523. else {
  524. tty_buffer_request_room(tty, len);
  525. tty_insert_flip_string(tty, buffer, len);
  526. tty_flip_buffer_push(tty);
  527. }
  528. spin_unlock_irqrestore(&cs->lock, flags);
  529. }
  530. EXPORT_SYMBOL_GPL(gigaset_if_receive);
  531. /* gigaset_if_initdriver
  532. * Initialize tty interface.
  533. * parameters:
  534. * drv Driver
  535. * procname Name of the driver (e.g. for /proc/tty/drivers)
  536. * devname Name of the device files (prefix without minor number)
  537. * devfsname Devfs name of the device files without %d
  538. */
  539. void gigaset_if_initdriver(struct gigaset_driver *drv, const char *procname,
  540. const char *devname, const char *devfsname)
  541. {
  542. unsigned minors = drv->minors;
  543. int ret;
  544. struct tty_driver *tty;
  545. drv->have_tty = 0;
  546. if ((drv->tty = alloc_tty_driver(minors)) == NULL)
  547. goto enomem;
  548. tty = drv->tty;
  549. tty->magic = TTY_DRIVER_MAGIC,
  550. tty->major = GIG_MAJOR,
  551. tty->type = TTY_DRIVER_TYPE_SERIAL,
  552. tty->subtype = SERIAL_TYPE_NORMAL,
  553. tty->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_NO_DEVFS,
  554. tty->driver_name = procname;
  555. tty->name = devname;
  556. tty->minor_start = drv->minor;
  557. tty->num = drv->minors;
  558. tty->owner = THIS_MODULE;
  559. tty->devfs_name = devfsname;
  560. tty->init_termios = tty_std_termios; //FIXME
  561. tty->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; //FIXME
  562. tty_set_operations(tty, &if_ops);
  563. ret = tty_register_driver(tty);
  564. if (ret < 0) {
  565. warn("failed to register tty driver (error %d)", ret);
  566. goto error;
  567. }
  568. gig_dbg(DEBUG_IF, "tty driver initialized");
  569. drv->have_tty = 1;
  570. return;
  571. enomem:
  572. warn("could not allocate tty structures");
  573. error:
  574. if (drv->tty)
  575. put_tty_driver(drv->tty);
  576. }
  577. void gigaset_if_freedriver(struct gigaset_driver *drv)
  578. {
  579. if (!drv->have_tty)
  580. return;
  581. drv->have_tty = 0;
  582. tty_unregister_driver(drv->tty);
  583. put_tty_driver(drv->tty);
  584. }