interface.c 16 KB

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