interface.c 16 KB

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