interface.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  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,
  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);
  102. static int if_tiocmset(struct tty_struct *tty,
  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,
  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)
  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,
  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. struct cmdbuf_t *cb;
  281. int retval;
  282. cs = (struct cardstate *) tty->driver_data;
  283. if (!cs) {
  284. pr_err("%s: no cardstate\n", __func__);
  285. return -ENODEV;
  286. }
  287. gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
  288. if (mutex_lock_interruptible(&cs->mutex))
  289. return -ERESTARTSYS;
  290. if (!cs->connected) {
  291. gig_dbg(DEBUG_IF, "not connected");
  292. retval = -ENODEV;
  293. goto done;
  294. }
  295. if (!cs->open_count) {
  296. dev_warn(cs->dev, "%s: device not opened\n", __func__);
  297. retval = -ENODEV;
  298. goto done;
  299. }
  300. if (cs->mstate != MS_LOCKED) {
  301. dev_warn(cs->dev, "can't write to unlocked device\n");
  302. retval = -EBUSY;
  303. goto done;
  304. }
  305. if (count <= 0) {
  306. /* nothing to do */
  307. retval = 0;
  308. goto done;
  309. }
  310. cb = kmalloc(sizeof(struct cmdbuf_t) + count, GFP_KERNEL);
  311. if (!cb) {
  312. dev_err(cs->dev, "%s: out of memory\n", __func__);
  313. retval = -ENOMEM;
  314. goto done;
  315. }
  316. memcpy(cb->buf, buf, count);
  317. cb->len = count;
  318. cb->offset = 0;
  319. cb->next = NULL;
  320. cb->wake_tasklet = &cs->if_wake_tasklet;
  321. retval = cs->ops->write_cmd(cs, cb);
  322. done:
  323. mutex_unlock(&cs->mutex);
  324. return retval;
  325. }
  326. static int if_write_room(struct tty_struct *tty)
  327. {
  328. struct cardstate *cs;
  329. int retval = -ENODEV;
  330. cs = (struct cardstate *) tty->driver_data;
  331. if (!cs) {
  332. pr_err("%s: no cardstate\n", __func__);
  333. return -ENODEV;
  334. }
  335. gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
  336. if (mutex_lock_interruptible(&cs->mutex))
  337. return -ERESTARTSYS;
  338. if (!cs->connected) {
  339. gig_dbg(DEBUG_IF, "not connected");
  340. retval = -ENODEV;
  341. } else if (!cs->open_count)
  342. dev_warn(cs->dev, "%s: device not opened\n", __func__);
  343. else if (cs->mstate != MS_LOCKED) {
  344. dev_warn(cs->dev, "can't write to unlocked device\n");
  345. retval = -EBUSY;
  346. } else
  347. retval = cs->ops->write_room(cs);
  348. mutex_unlock(&cs->mutex);
  349. return retval;
  350. }
  351. static int if_chars_in_buffer(struct tty_struct *tty)
  352. {
  353. struct cardstate *cs;
  354. int retval = 0;
  355. cs = (struct cardstate *) tty->driver_data;
  356. if (!cs) {
  357. pr_err("%s: no cardstate\n", __func__);
  358. return 0;
  359. }
  360. gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
  361. mutex_lock(&cs->mutex);
  362. if (!cs->connected)
  363. gig_dbg(DEBUG_IF, "not connected");
  364. else if (!cs->open_count)
  365. dev_warn(cs->dev, "%s: device not opened\n", __func__);
  366. else if (cs->mstate != MS_LOCKED)
  367. dev_warn(cs->dev, "can't write to unlocked device\n");
  368. else
  369. retval = cs->ops->chars_in_buffer(cs);
  370. mutex_unlock(&cs->mutex);
  371. return retval;
  372. }
  373. static void if_throttle(struct tty_struct *tty)
  374. {
  375. struct cardstate *cs;
  376. cs = (struct cardstate *) tty->driver_data;
  377. if (!cs) {
  378. pr_err("%s: no cardstate\n", __func__);
  379. return;
  380. }
  381. gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
  382. mutex_lock(&cs->mutex);
  383. if (!cs->connected)
  384. gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
  385. else if (!cs->open_count)
  386. dev_warn(cs->dev, "%s: device not opened\n", __func__);
  387. else
  388. gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
  389. mutex_unlock(&cs->mutex);
  390. }
  391. static void if_unthrottle(struct tty_struct *tty)
  392. {
  393. struct cardstate *cs;
  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"); /* nothing to do */
  403. else if (!cs->open_count)
  404. dev_warn(cs->dev, "%s: device not opened\n", __func__);
  405. else
  406. gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
  407. mutex_unlock(&cs->mutex);
  408. }
  409. static void if_set_termios(struct tty_struct *tty, struct ktermios *old)
  410. {
  411. struct cardstate *cs;
  412. unsigned int iflag;
  413. unsigned int cflag;
  414. unsigned int old_cflag;
  415. unsigned int control_state, new_state;
  416. cs = (struct cardstate *) tty->driver_data;
  417. if (!cs) {
  418. pr_err("%s: no cardstate\n", __func__);
  419. return;
  420. }
  421. gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
  422. mutex_lock(&cs->mutex);
  423. if (!cs->connected) {
  424. gig_dbg(DEBUG_IF, "not connected");
  425. goto out;
  426. }
  427. if (!cs->open_count) {
  428. dev_warn(cs->dev, "%s: device not opened\n", __func__);
  429. goto out;
  430. }
  431. iflag = tty->termios->c_iflag;
  432. cflag = tty->termios->c_cflag;
  433. old_cflag = old ? old->c_cflag : cflag;
  434. gig_dbg(DEBUG_IF, "%u: iflag %x cflag %x old %x",
  435. cs->minor_index, iflag, cflag, old_cflag);
  436. /* get a local copy of the current port settings */
  437. control_state = cs->control_state;
  438. /*
  439. * Update baud rate.
  440. * Do not attempt to cache old rates and skip settings,
  441. * disconnects screw such tricks up completely.
  442. * Premature optimization is the root of all evil.
  443. */
  444. /* reassert DTR and (maybe) RTS on transition from B0 */
  445. if ((old_cflag & CBAUD) == B0) {
  446. new_state = control_state | TIOCM_DTR;
  447. /* don't set RTS if using hardware flow control */
  448. if (!(old_cflag & CRTSCTS))
  449. new_state |= TIOCM_RTS;
  450. gig_dbg(DEBUG_IF, "%u: from B0 - set DTR%s",
  451. cs->minor_index,
  452. (new_state & TIOCM_RTS) ? " only" : "/RTS");
  453. cs->ops->set_modem_ctrl(cs, control_state, new_state);
  454. control_state = new_state;
  455. }
  456. cs->ops->baud_rate(cs, cflag & CBAUD);
  457. if ((cflag & CBAUD) == B0) {
  458. /* Drop RTS and DTR */
  459. gig_dbg(DEBUG_IF, "%u: to B0 - drop DTR/RTS", cs->minor_index);
  460. new_state = control_state & ~(TIOCM_DTR | TIOCM_RTS);
  461. cs->ops->set_modem_ctrl(cs, control_state, new_state);
  462. control_state = new_state;
  463. }
  464. /*
  465. * Update line control register (LCR)
  466. */
  467. cs->ops->set_line_ctrl(cs, cflag);
  468. /* save off the modified port settings */
  469. cs->control_state = control_state;
  470. out:
  471. mutex_unlock(&cs->mutex);
  472. }
  473. /* wakeup tasklet for the write operation */
  474. static void if_wake(unsigned long data)
  475. {
  476. struct cardstate *cs = (struct cardstate *) data;
  477. if (cs->tty)
  478. tty_wakeup(cs->tty);
  479. }
  480. /*** interface to common ***/
  481. void gigaset_if_init(struct cardstate *cs)
  482. {
  483. struct gigaset_driver *drv;
  484. drv = cs->driver;
  485. if (!drv->have_tty)
  486. return;
  487. tasklet_init(&cs->if_wake_tasklet, if_wake, (unsigned long) cs);
  488. mutex_lock(&cs->mutex);
  489. cs->tty_dev = tty_register_device(drv->tty, cs->minor_index, NULL);
  490. if (!IS_ERR(cs->tty_dev))
  491. dev_set_drvdata(cs->tty_dev, cs);
  492. else {
  493. pr_warning("could not register device to the tty subsystem\n");
  494. cs->tty_dev = NULL;
  495. }
  496. mutex_unlock(&cs->mutex);
  497. }
  498. void gigaset_if_free(struct cardstate *cs)
  499. {
  500. struct gigaset_driver *drv;
  501. drv = cs->driver;
  502. if (!drv->have_tty)
  503. return;
  504. tasklet_disable(&cs->if_wake_tasklet);
  505. tasklet_kill(&cs->if_wake_tasklet);
  506. cs->tty_dev = NULL;
  507. tty_unregister_device(drv->tty, cs->minor_index);
  508. }
  509. /**
  510. * gigaset_if_receive() - pass a received block of data to the tty device
  511. * @cs: device descriptor structure.
  512. * @buffer: received data.
  513. * @len: number of bytes received.
  514. *
  515. * Called by asyncdata/isocdata if a block of data received from the
  516. * device must be sent to userspace through the ttyG* device.
  517. */
  518. void gigaset_if_receive(struct cardstate *cs,
  519. unsigned char *buffer, size_t len)
  520. {
  521. unsigned long flags;
  522. struct tty_struct *tty;
  523. spin_lock_irqsave(&cs->lock, flags);
  524. tty = cs->tty;
  525. if (tty == NULL)
  526. gig_dbg(DEBUG_IF, "receive on closed device");
  527. else {
  528. tty_insert_flip_string(tty, buffer, len);
  529. tty_flip_buffer_push(tty);
  530. }
  531. spin_unlock_irqrestore(&cs->lock, flags);
  532. }
  533. EXPORT_SYMBOL_GPL(gigaset_if_receive);
  534. /* gigaset_if_initdriver
  535. * Initialize tty interface.
  536. * parameters:
  537. * drv Driver
  538. * procname Name of the driver (e.g. for /proc/tty/drivers)
  539. * devname Name of the device files (prefix without minor number)
  540. */
  541. void gigaset_if_initdriver(struct gigaset_driver *drv, const char *procname,
  542. const char *devname)
  543. {
  544. unsigned minors = drv->minors;
  545. int ret;
  546. struct tty_driver *tty;
  547. drv->have_tty = 0;
  548. drv->tty = tty = alloc_tty_driver(minors);
  549. if (tty == NULL)
  550. goto enomem;
  551. tty->magic = TTY_DRIVER_MAGIC,
  552. tty->type = TTY_DRIVER_TYPE_SERIAL,
  553. tty->subtype = SERIAL_TYPE_NORMAL,
  554. tty->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
  555. tty->driver_name = procname;
  556. tty->name = devname;
  557. tty->minor_start = drv->minor;
  558. tty->num = drv->minors;
  559. tty->owner = THIS_MODULE;
  560. tty->init_termios = tty_std_termios;
  561. tty->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
  562. tty_set_operations(tty, &if_ops);
  563. ret = tty_register_driver(tty);
  564. if (ret < 0) {
  565. pr_err("error %d registering tty driver\n", ret);
  566. goto error;
  567. }
  568. gig_dbg(DEBUG_IF, "tty driver initialized");
  569. drv->have_tty = 1;
  570. return;
  571. enomem:
  572. pr_err("out of memory\n");
  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. }