interface.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  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 = cs->mstate == MS_LOCKED;
  26. return 0;
  27. }
  28. if (!cmd && cs->mstate == MS_LOCKED && cs->connected) {
  29. cs->ops->set_modem_ctrl(cs, 0, TIOCM_DTR|TIOCM_RTS);
  30. cs->ops->baud_rate(cs, B115200);
  31. cs->ops->set_line_ctrl(cs, CS8);
  32. cs->control_state = TIOCM_DTR|TIOCM_RTS;
  33. }
  34. cs->waiting = 1;
  35. if (!gigaset_add_event(cs, &cs->at_state, EV_IF_LOCK,
  36. NULL, cmd, NULL)) {
  37. cs->waiting = 0;
  38. return -ENOMEM;
  39. }
  40. gig_dbg(DEBUG_CMD, "scheduling IF_LOCK");
  41. gigaset_schedule_event(cs);
  42. wait_event(cs->waitqueue, !cs->waiting);
  43. if (cs->cmd_result >= 0) {
  44. *arg = cs->cmd_result;
  45. return 0;
  46. }
  47. return cs->cmd_result;
  48. }
  49. static int if_version(struct cardstate *cs, unsigned arg[4])
  50. {
  51. static const unsigned version[4] = GIG_VERSION;
  52. static const unsigned compat[4] = GIG_COMPAT;
  53. unsigned cmd = arg[0];
  54. gig_dbg(DEBUG_IF, "%u: if_version (%d)", cs->minor_index, cmd);
  55. switch (cmd) {
  56. case GIGVER_DRIVER:
  57. memcpy(arg, version, sizeof version);
  58. return 0;
  59. case GIGVER_COMPAT:
  60. memcpy(arg, compat, sizeof compat);
  61. return 0;
  62. case GIGVER_FWBASE:
  63. cs->waiting = 1;
  64. if (!gigaset_add_event(cs, &cs->at_state, EV_IF_VER,
  65. NULL, 0, arg)) {
  66. cs->waiting = 0;
  67. return -ENOMEM;
  68. }
  69. gig_dbg(DEBUG_CMD, "scheduling IF_VER");
  70. gigaset_schedule_event(cs);
  71. wait_event(cs->waitqueue, !cs->waiting);
  72. if (cs->cmd_result >= 0)
  73. return 0;
  74. return cs->cmd_result;
  75. default:
  76. return -EINVAL;
  77. }
  78. }
  79. static int if_config(struct cardstate *cs, int *arg)
  80. {
  81. gig_dbg(DEBUG_IF, "%u: if_config (%d)", cs->minor_index, *arg);
  82. if (*arg != 1)
  83. return -EINVAL;
  84. if (cs->mstate != MS_LOCKED)
  85. return -EBUSY;
  86. if (!cs->connected) {
  87. pr_err("%s: not connected\n", __func__);
  88. return -ENODEV;
  89. }
  90. *arg = 0;
  91. return gigaset_enterconfigmode(cs);
  92. }
  93. /*** the terminal driver ***/
  94. /* stolen from usbserial and some other tty drivers */
  95. static int if_open(struct tty_struct *tty, struct file *filp);
  96. static void if_close(struct tty_struct *tty, struct file *filp);
  97. static int if_ioctl(struct tty_struct *tty, struct file *file,
  98. unsigned int cmd, unsigned long arg);
  99. static int if_write_room(struct tty_struct *tty);
  100. static int if_chars_in_buffer(struct tty_struct *tty);
  101. static void if_throttle(struct tty_struct *tty);
  102. static void if_unthrottle(struct tty_struct *tty);
  103. static void if_set_termios(struct tty_struct *tty, struct ktermios *old);
  104. static int if_tiocmget(struct tty_struct *tty, struct file *file);
  105. static int if_tiocmset(struct tty_struct *tty, struct file *file,
  106. unsigned int set, unsigned int clear);
  107. static int if_write(struct tty_struct *tty,
  108. const unsigned char *buf, int count);
  109. static const struct tty_operations if_ops = {
  110. .open = if_open,
  111. .close = if_close,
  112. .ioctl = if_ioctl,
  113. .write = if_write,
  114. .write_room = if_write_room,
  115. .chars_in_buffer = if_chars_in_buffer,
  116. .set_termios = if_set_termios,
  117. .throttle = if_throttle,
  118. .unthrottle = if_unthrottle,
  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 || !try_module_get(cs->driver->owner))
  131. return -ENODEV;
  132. if (mutex_lock_interruptible(&cs->mutex))
  133. return -ERESTARTSYS;
  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;
  141. }
  142. mutex_unlock(&cs->mutex);
  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. pr_err("%s: no cardstate\n", __func__);
  152. return;
  153. }
  154. gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
  155. mutex_lock(&cs->mutex);
  156. if (!cs->connected)
  157. gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
  158. else if (!cs->open_count)
  159. dev_warn(cs->dev, "%s: device not opened\n", __func__);
  160. else {
  161. if (!--cs->open_count) {
  162. spin_lock_irqsave(&cs->lock, flags);
  163. cs->tty = NULL;
  164. spin_unlock_irqrestore(&cs->lock, flags);
  165. }
  166. }
  167. mutex_unlock(&cs->mutex);
  168. module_put(cs->driver->owner);
  169. }
  170. static int if_ioctl(struct tty_struct *tty, struct file *file,
  171. unsigned int cmd, unsigned long arg)
  172. {
  173. struct cardstate *cs;
  174. int retval = -ENODEV;
  175. int int_arg;
  176. unsigned char buf[6];
  177. unsigned version[4];
  178. cs = (struct cardstate *) tty->driver_data;
  179. if (!cs) {
  180. pr_err("%s: no cardstate\n", __func__);
  181. return -ENODEV;
  182. }
  183. gig_dbg(DEBUG_IF, "%u: %s(0x%x)", cs->minor_index, __func__, cmd);
  184. if (mutex_lock_interruptible(&cs->mutex))
  185. return -ERESTARTSYS;
  186. if (!cs->connected) {
  187. gig_dbg(DEBUG_IF, "not connected");
  188. retval = -ENODEV;
  189. } else if (!cs->open_count)
  190. dev_warn(cs->dev, "%s: device not opened\n", __func__);
  191. else {
  192. retval = 0;
  193. switch (cmd) {
  194. case GIGASET_REDIR:
  195. retval = get_user(int_arg, (int __user *) arg);
  196. if (retval >= 0)
  197. retval = if_lock(cs, &int_arg);
  198. if (retval >= 0)
  199. retval = put_user(int_arg, (int __user *) arg);
  200. break;
  201. case GIGASET_CONFIG:
  202. retval = get_user(int_arg, (int __user *) arg);
  203. if (retval >= 0)
  204. retval = if_config(cs, &int_arg);
  205. if (retval >= 0)
  206. retval = put_user(int_arg, (int __user *) arg);
  207. break;
  208. case GIGASET_BRKCHARS:
  209. retval = copy_from_user(&buf,
  210. (const unsigned char __user *) arg, 6)
  211. ? -EFAULT : 0;
  212. if (retval >= 0) {
  213. gigaset_dbg_buffer(DEBUG_IF, "GIGASET_BRKCHARS",
  214. 6, (const unsigned char *) arg);
  215. retval = cs->ops->brkchars(cs, buf);
  216. }
  217. break;
  218. case GIGASET_VERSION:
  219. retval = copy_from_user(version,
  220. (unsigned __user *) arg, sizeof version)
  221. ? -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. gig_dbg(DEBUG_ANY, "%s: arg not supported - 0x%04x",
  231. __func__, cmd);
  232. retval = -ENOIOCTLCMD;
  233. }
  234. }
  235. mutex_unlock(&cs->mutex);
  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. pr_err("%s: no cardstate\n", __func__);
  245. return -ENODEV;
  246. }
  247. gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
  248. if (mutex_lock_interruptible(&cs->mutex))
  249. return -ERESTARTSYS;
  250. retval = cs->control_state & (TIOCM_RTS|TIOCM_DTR);
  251. mutex_unlock(&cs->mutex);
  252. return retval;
  253. }
  254. static int if_tiocmset(struct tty_struct *tty, struct file *file,
  255. unsigned int set, unsigned int clear)
  256. {
  257. struct cardstate *cs;
  258. int retval;
  259. unsigned mc;
  260. cs = (struct cardstate *) tty->driver_data;
  261. if (!cs) {
  262. pr_err("%s: no cardstate\n", __func__);
  263. return -ENODEV;
  264. }
  265. gig_dbg(DEBUG_IF, "%u: %s(0x%x, 0x%x)",
  266. cs->minor_index, __func__, set, clear);
  267. if (mutex_lock_interruptible(&cs->mutex))
  268. return -ERESTARTSYS;
  269. if (!cs->connected) {
  270. gig_dbg(DEBUG_IF, "not connected");
  271. retval = -ENODEV;
  272. } else {
  273. mc = (cs->control_state | set) & ~clear & (TIOCM_RTS|TIOCM_DTR);
  274. retval = cs->ops->set_modem_ctrl(cs, cs->control_state, mc);
  275. cs->control_state = mc;
  276. }
  277. mutex_unlock(&cs->mutex);
  278. return retval;
  279. }
  280. static int if_write(struct tty_struct *tty, const unsigned char *buf, int count)
  281. {
  282. struct cardstate *cs;
  283. int retval = -ENODEV;
  284. cs = (struct cardstate *) tty->driver_data;
  285. if (!cs) {
  286. pr_err("%s: no cardstate\n", __func__);
  287. return -ENODEV;
  288. }
  289. gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
  290. if (mutex_lock_interruptible(&cs->mutex))
  291. return -ERESTARTSYS;
  292. if (!cs->connected) {
  293. gig_dbg(DEBUG_IF, "not connected");
  294. retval = -ENODEV;
  295. } else if (!cs->open_count)
  296. dev_warn(cs->dev, "%s: device not opened\n", __func__);
  297. else if (cs->mstate != MS_LOCKED) {
  298. dev_warn(cs->dev, "can't write to unlocked device\n");
  299. retval = -EBUSY;
  300. } else {
  301. retval = cs->ops->write_cmd(cs, buf, count,
  302. &cs->if_wake_tasklet);
  303. }
  304. mutex_unlock(&cs->mutex);
  305. return retval;
  306. }
  307. static int if_write_room(struct tty_struct *tty)
  308. {
  309. struct cardstate *cs;
  310. int retval = -ENODEV;
  311. cs = (struct cardstate *) tty->driver_data;
  312. if (!cs) {
  313. pr_err("%s: no cardstate\n", __func__);
  314. return -ENODEV;
  315. }
  316. gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
  317. if (mutex_lock_interruptible(&cs->mutex))
  318. return -ERESTARTSYS;
  319. if (!cs->connected) {
  320. gig_dbg(DEBUG_IF, "not connected");
  321. retval = -ENODEV;
  322. } else if (!cs->open_count)
  323. dev_warn(cs->dev, "%s: device not opened\n", __func__);
  324. else if (cs->mstate != MS_LOCKED) {
  325. dev_warn(cs->dev, "can't write to unlocked device\n");
  326. retval = -EBUSY;
  327. } else
  328. retval = cs->ops->write_room(cs);
  329. mutex_unlock(&cs->mutex);
  330. return retval;
  331. }
  332. static int if_chars_in_buffer(struct tty_struct *tty)
  333. {
  334. struct cardstate *cs;
  335. int retval = 0;
  336. cs = (struct cardstate *) tty->driver_data;
  337. if (!cs) {
  338. pr_err("%s: no cardstate\n", __func__);
  339. return 0;
  340. }
  341. gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
  342. mutex_lock(&cs->mutex);
  343. if (!cs->connected)
  344. gig_dbg(DEBUG_IF, "not connected");
  345. else if (!cs->open_count)
  346. dev_warn(cs->dev, "%s: device not opened\n", __func__);
  347. else if (cs->mstate != MS_LOCKED)
  348. dev_warn(cs->dev, "can't write to unlocked device\n");
  349. else
  350. retval = cs->ops->chars_in_buffer(cs);
  351. mutex_unlock(&cs->mutex);
  352. return retval;
  353. }
  354. static void if_throttle(struct tty_struct *tty)
  355. {
  356. struct cardstate *cs;
  357. cs = (struct cardstate *) tty->driver_data;
  358. if (!cs) {
  359. pr_err("%s: no cardstate\n", __func__);
  360. return;
  361. }
  362. gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
  363. mutex_lock(&cs->mutex);
  364. if (!cs->connected)
  365. gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
  366. else if (!cs->open_count)
  367. dev_warn(cs->dev, "%s: device not opened\n", __func__);
  368. else
  369. gig_dbg(DEBUG_ANY, "%s: not implemented\n", __func__);
  370. mutex_unlock(&cs->mutex);
  371. }
  372. static void if_unthrottle(struct tty_struct *tty)
  373. {
  374. struct cardstate *cs;
  375. cs = (struct cardstate *) tty->driver_data;
  376. if (!cs) {
  377. pr_err("%s: no cardstate\n", __func__);
  378. return;
  379. }
  380. gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
  381. mutex_lock(&cs->mutex);
  382. if (!cs->connected)
  383. gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
  384. else if (!cs->open_count)
  385. dev_warn(cs->dev, "%s: device not opened\n", __func__);
  386. else
  387. gig_dbg(DEBUG_ANY, "%s: not implemented\n", __func__);
  388. mutex_unlock(&cs->mutex);
  389. }
  390. static void if_set_termios(struct tty_struct *tty, struct ktermios *old)
  391. {
  392. struct cardstate *cs;
  393. unsigned int iflag;
  394. unsigned int cflag;
  395. unsigned int old_cflag;
  396. unsigned int control_state, new_state;
  397. cs = (struct cardstate *) tty->driver_data;
  398. if (!cs) {
  399. pr_err("%s: no cardstate\n", __func__);
  400. return;
  401. }
  402. gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
  403. mutex_lock(&cs->mutex);
  404. if (!cs->connected) {
  405. gig_dbg(DEBUG_IF, "not connected");
  406. goto out;
  407. }
  408. if (!cs->open_count) {
  409. dev_warn(cs->dev, "%s: device not opened\n", __func__);
  410. goto out;
  411. }
  412. iflag = tty->termios->c_iflag;
  413. cflag = tty->termios->c_cflag;
  414. old_cflag = old ? old->c_cflag : cflag;
  415. gig_dbg(DEBUG_IF, "%u: iflag %x cflag %x old %x",
  416. cs->minor_index, iflag, cflag, old_cflag);
  417. /* get a local copy of the current port settings */
  418. control_state = cs->control_state;
  419. /*
  420. * Update baud rate.
  421. * Do not attempt to cache old rates and skip settings,
  422. * disconnects screw such tricks up completely.
  423. * Premature optimization is the root of all evil.
  424. */
  425. /* reassert DTR and (maybe) RTS on transition from B0 */
  426. if ((old_cflag & CBAUD) == B0) {
  427. new_state = control_state | TIOCM_DTR;
  428. /* don't set RTS if using hardware flow control */
  429. if (!(old_cflag & CRTSCTS))
  430. new_state |= TIOCM_RTS;
  431. gig_dbg(DEBUG_IF, "%u: from B0 - set DTR%s",
  432. cs->minor_index,
  433. (new_state & TIOCM_RTS) ? " only" : "/RTS");
  434. cs->ops->set_modem_ctrl(cs, control_state, new_state);
  435. control_state = new_state;
  436. }
  437. cs->ops->baud_rate(cs, cflag & CBAUD);
  438. if ((cflag & CBAUD) == B0) {
  439. /* Drop RTS and DTR */
  440. gig_dbg(DEBUG_IF, "%u: to B0 - drop DTR/RTS", cs->minor_index);
  441. new_state = control_state & ~(TIOCM_DTR | TIOCM_RTS);
  442. cs->ops->set_modem_ctrl(cs, control_state, new_state);
  443. control_state = new_state;
  444. }
  445. /*
  446. * Update line control register (LCR)
  447. */
  448. cs->ops->set_line_ctrl(cs, cflag);
  449. /* save off the modified port settings */
  450. cs->control_state = control_state;
  451. out:
  452. mutex_unlock(&cs->mutex);
  453. }
  454. /* wakeup tasklet for the write operation */
  455. static void if_wake(unsigned long data)
  456. {
  457. struct cardstate *cs = (struct cardstate *) data;
  458. if (cs->tty)
  459. tty_wakeup(cs->tty);
  460. }
  461. /*** interface to common ***/
  462. void gigaset_if_init(struct cardstate *cs)
  463. {
  464. struct gigaset_driver *drv;
  465. drv = cs->driver;
  466. if (!drv->have_tty)
  467. return;
  468. tasklet_init(&cs->if_wake_tasklet, if_wake, (unsigned long) cs);
  469. mutex_lock(&cs->mutex);
  470. cs->tty_dev = tty_register_device(drv->tty, cs->minor_index, NULL);
  471. if (!IS_ERR(cs->tty_dev))
  472. dev_set_drvdata(cs->tty_dev, cs);
  473. else {
  474. pr_warning("could not register device to the tty subsystem\n");
  475. cs->tty_dev = NULL;
  476. }
  477. mutex_unlock(&cs->mutex);
  478. }
  479. void gigaset_if_free(struct cardstate *cs)
  480. {
  481. struct gigaset_driver *drv;
  482. drv = cs->driver;
  483. if (!drv->have_tty)
  484. return;
  485. tasklet_disable(&cs->if_wake_tasklet);
  486. tasklet_kill(&cs->if_wake_tasklet);
  487. cs->tty_dev = NULL;
  488. tty_unregister_device(drv->tty, cs->minor_index);
  489. }
  490. /**
  491. * gigaset_if_receive() - pass a received block of data to the tty device
  492. * @cs: device descriptor structure.
  493. * @buffer: received data.
  494. * @len: number of bytes received.
  495. *
  496. * Called by asyncdata/isocdata if a block of data received from the
  497. * device must be sent to userspace through the ttyG* device.
  498. */
  499. void gigaset_if_receive(struct cardstate *cs,
  500. unsigned char *buffer, size_t len)
  501. {
  502. unsigned long flags;
  503. struct tty_struct *tty;
  504. spin_lock_irqsave(&cs->lock, flags);
  505. tty = cs->tty;
  506. if (tty == NULL)
  507. gig_dbg(DEBUG_ANY, "receive on closed device");
  508. else {
  509. tty_buffer_request_room(tty, len);
  510. tty_insert_flip_string(tty, buffer, len);
  511. tty_flip_buffer_push(tty);
  512. }
  513. spin_unlock_irqrestore(&cs->lock, flags);
  514. }
  515. EXPORT_SYMBOL_GPL(gigaset_if_receive);
  516. /* gigaset_if_initdriver
  517. * Initialize tty interface.
  518. * parameters:
  519. * drv Driver
  520. * procname Name of the driver (e.g. for /proc/tty/drivers)
  521. * devname Name of the device files (prefix without minor number)
  522. */
  523. void gigaset_if_initdriver(struct gigaset_driver *drv, const char *procname,
  524. const char *devname)
  525. {
  526. unsigned minors = drv->minors;
  527. int ret;
  528. struct tty_driver *tty;
  529. drv->have_tty = 0;
  530. drv->tty = tty = alloc_tty_driver(minors);
  531. if (tty == NULL)
  532. goto enomem;
  533. tty->magic = TTY_DRIVER_MAGIC,
  534. tty->major = GIG_MAJOR,
  535. tty->type = TTY_DRIVER_TYPE_SERIAL,
  536. tty->subtype = SERIAL_TYPE_NORMAL,
  537. tty->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
  538. tty->driver_name = procname;
  539. tty->name = devname;
  540. tty->minor_start = drv->minor;
  541. tty->num = drv->minors;
  542. tty->owner = THIS_MODULE;
  543. tty->init_termios = tty_std_termios;
  544. tty->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
  545. tty_set_operations(tty, &if_ops);
  546. ret = tty_register_driver(tty);
  547. if (ret < 0) {
  548. pr_err("error %d registering tty driver\n", ret);
  549. goto error;
  550. }
  551. gig_dbg(DEBUG_IF, "tty driver initialized");
  552. drv->have_tty = 1;
  553. return;
  554. enomem:
  555. pr_err("out of memory\n");
  556. error:
  557. if (drv->tty)
  558. put_tty_driver(drv->tty);
  559. }
  560. void gigaset_if_freedriver(struct gigaset_driver *drv)
  561. {
  562. if (!drv->have_tty)
  563. return;
  564. drv->have_tty = 0;
  565. tty_unregister_driver(drv->tty);
  566. put_tty_driver(drv->tty);
  567. }