interface.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  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; // 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. 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; // FIXME -EINTR?
  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; // FIXME -EINTR?
  250. // FIXME read from device?
  251. retval = cs->control_state & (TIOCM_RTS|TIOCM_DTR);
  252. mutex_unlock(&cs->mutex);
  253. return retval;
  254. }
  255. static int if_tiocmset(struct tty_struct *tty, struct file *file,
  256. unsigned int set, unsigned int clear)
  257. {
  258. struct cardstate *cs;
  259. int retval;
  260. unsigned mc;
  261. cs = (struct cardstate *) tty->driver_data;
  262. if (!cs) {
  263. pr_err("%s: no cardstate\n", __func__);
  264. return -ENODEV;
  265. }
  266. gig_dbg(DEBUG_IF, "%u: %s(0x%x, 0x%x)",
  267. cs->minor_index, __func__, set, clear);
  268. if (mutex_lock_interruptible(&cs->mutex))
  269. return -ERESTARTSYS; // FIXME -EINTR?
  270. if (!cs->connected) {
  271. gig_dbg(DEBUG_IF, "not connected");
  272. retval = -ENODEV;
  273. } else {
  274. mc = (cs->control_state | set) & ~clear & (TIOCM_RTS|TIOCM_DTR);
  275. retval = cs->ops->set_modem_ctrl(cs, cs->control_state, mc);
  276. cs->control_state = mc;
  277. }
  278. mutex_unlock(&cs->mutex);
  279. return retval;
  280. }
  281. static int if_write(struct tty_struct *tty, const unsigned char *buf, int count)
  282. {
  283. struct cardstate *cs;
  284. int retval = -ENODEV;
  285. cs = (struct cardstate *) tty->driver_data;
  286. if (!cs) {
  287. pr_err("%s: no cardstate\n", __func__);
  288. return -ENODEV;
  289. }
  290. gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
  291. if (mutex_lock_interruptible(&cs->mutex))
  292. return -ERESTARTSYS; // FIXME -EINTR?
  293. if (!cs->connected) {
  294. gig_dbg(DEBUG_IF, "not connected");
  295. retval = -ENODEV;
  296. } else if (!cs->open_count)
  297. dev_warn(cs->dev, "%s: device not opened\n", __func__);
  298. else if (cs->mstate != MS_LOCKED) {
  299. dev_warn(cs->dev, "can't write to unlocked device\n");
  300. retval = -EBUSY;
  301. } else {
  302. retval = cs->ops->write_cmd(cs, buf, count,
  303. &cs->if_wake_tasklet);
  304. }
  305. mutex_unlock(&cs->mutex);
  306. return retval;
  307. }
  308. static int if_write_room(struct tty_struct *tty)
  309. {
  310. struct cardstate *cs;
  311. int retval = -ENODEV;
  312. cs = (struct cardstate *) tty->driver_data;
  313. if (!cs) {
  314. pr_err("%s: no cardstate\n", __func__);
  315. return -ENODEV;
  316. }
  317. gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
  318. if (mutex_lock_interruptible(&cs->mutex))
  319. return -ERESTARTSYS; // FIXME -EINTR?
  320. if (!cs->connected) {
  321. gig_dbg(DEBUG_IF, "not connected");
  322. retval = -ENODEV;
  323. } else if (!cs->open_count)
  324. dev_warn(cs->dev, "%s: device not opened\n", __func__);
  325. else if (cs->mstate != MS_LOCKED) {
  326. dev_warn(cs->dev, "can't write to unlocked device\n");
  327. retval = -EBUSY;
  328. } else
  329. retval = cs->ops->write_room(cs);
  330. mutex_unlock(&cs->mutex);
  331. return retval;
  332. }
  333. static int if_chars_in_buffer(struct tty_struct *tty)
  334. {
  335. struct cardstate *cs;
  336. int retval = 0;
  337. cs = (struct cardstate *) tty->driver_data;
  338. if (!cs) {
  339. pr_err("%s: no cardstate\n", __func__);
  340. return 0;
  341. }
  342. gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
  343. mutex_lock(&cs->mutex);
  344. if (!cs->connected)
  345. gig_dbg(DEBUG_IF, "not connected");
  346. else if (!cs->open_count)
  347. dev_warn(cs->dev, "%s: device not opened\n", __func__);
  348. else if (cs->mstate != MS_LOCKED)
  349. dev_warn(cs->dev, "can't write to unlocked device\n");
  350. else
  351. retval = cs->ops->chars_in_buffer(cs);
  352. mutex_unlock(&cs->mutex);
  353. return retval;
  354. }
  355. static void if_throttle(struct tty_struct *tty)
  356. {
  357. struct cardstate *cs;
  358. cs = (struct cardstate *) tty->driver_data;
  359. if (!cs) {
  360. pr_err("%s: no cardstate\n", __func__);
  361. return;
  362. }
  363. gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
  364. mutex_lock(&cs->mutex);
  365. if (!cs->connected)
  366. gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
  367. else if (!cs->open_count)
  368. dev_warn(cs->dev, "%s: device not opened\n", __func__);
  369. else {
  370. //FIXME
  371. }
  372. mutex_unlock(&cs->mutex);
  373. }
  374. static void if_unthrottle(struct tty_struct *tty)
  375. {
  376. struct cardstate *cs;
  377. cs = (struct cardstate *) tty->driver_data;
  378. if (!cs) {
  379. pr_err("%s: no cardstate\n", __func__);
  380. return;
  381. }
  382. gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
  383. mutex_lock(&cs->mutex);
  384. if (!cs->connected)
  385. gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
  386. else if (!cs->open_count)
  387. dev_warn(cs->dev, "%s: device not opened\n", __func__);
  388. else {
  389. //FIXME
  390. }
  391. mutex_unlock(&cs->mutex);
  392. }
  393. static void if_set_termios(struct tty_struct *tty, struct ktermios *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. pr_err("%s: no cardstate\n", __func__);
  403. return;
  404. }
  405. gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
  406. mutex_lock(&cs->mutex);
  407. if (!cs->connected) {
  408. gig_dbg(DEBUG_IF, "not connected");
  409. goto out;
  410. }
  411. if (!cs->open_count) {
  412. dev_warn(cs->dev, "%s: device not opened\n", __func__);
  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. /* save off the modified port settings */
  454. cs->control_state = control_state;
  455. out:
  456. mutex_unlock(&cs->mutex);
  457. }
  458. /* wakeup tasklet for the write operation */
  459. static void if_wake(unsigned long data)
  460. {
  461. struct cardstate *cs = (struct cardstate *) data;
  462. if (cs->tty)
  463. tty_wakeup(cs->tty);
  464. }
  465. /*** interface to common ***/
  466. void gigaset_if_init(struct cardstate *cs)
  467. {
  468. struct gigaset_driver *drv;
  469. drv = cs->driver;
  470. if (!drv->have_tty)
  471. return;
  472. tasklet_init(&cs->if_wake_tasklet, &if_wake, (unsigned long) cs);
  473. mutex_lock(&cs->mutex);
  474. cs->tty_dev = tty_register_device(drv->tty, cs->minor_index, NULL);
  475. if (!IS_ERR(cs->tty_dev))
  476. dev_set_drvdata(cs->tty_dev, cs);
  477. else {
  478. pr_warning("could not register device to the tty subsystem\n");
  479. cs->tty_dev = NULL;
  480. }
  481. mutex_unlock(&cs->mutex);
  482. }
  483. void gigaset_if_free(struct cardstate *cs)
  484. {
  485. struct gigaset_driver *drv;
  486. drv = cs->driver;
  487. if (!drv->have_tty)
  488. return;
  489. tasklet_disable(&cs->if_wake_tasklet);
  490. tasklet_kill(&cs->if_wake_tasklet);
  491. cs->tty_dev = NULL;
  492. tty_unregister_device(drv->tty, cs->minor_index);
  493. }
  494. /**
  495. * gigaset_if_receive() - pass a received block of data to the tty device
  496. * @cs: device descriptor structure.
  497. * @buffer: received data.
  498. * @len: number of bytes received.
  499. *
  500. * Called by asyncdata/isocdata if a block of data received from the
  501. * device must be sent to userspace through the ttyG* device.
  502. */
  503. void gigaset_if_receive(struct cardstate *cs,
  504. unsigned char *buffer, size_t len)
  505. {
  506. unsigned long flags;
  507. struct tty_struct *tty;
  508. spin_lock_irqsave(&cs->lock, flags);
  509. if ((tty = cs->tty) == NULL)
  510. gig_dbg(DEBUG_ANY, "receive on closed device");
  511. else {
  512. tty_buffer_request_room(tty, len);
  513. tty_insert_flip_string(tty, buffer, len);
  514. tty_flip_buffer_push(tty);
  515. }
  516. spin_unlock_irqrestore(&cs->lock, flags);
  517. }
  518. EXPORT_SYMBOL_GPL(gigaset_if_receive);
  519. /* gigaset_if_initdriver
  520. * Initialize tty interface.
  521. * parameters:
  522. * drv Driver
  523. * procname Name of the driver (e.g. for /proc/tty/drivers)
  524. * devname Name of the device files (prefix without minor number)
  525. */
  526. void gigaset_if_initdriver(struct gigaset_driver *drv, const char *procname,
  527. const char *devname)
  528. {
  529. unsigned minors = drv->minors;
  530. int ret;
  531. struct tty_driver *tty;
  532. drv->have_tty = 0;
  533. if ((drv->tty = alloc_tty_driver(minors)) == NULL)
  534. goto enomem;
  535. tty = drv->tty;
  536. tty->magic = TTY_DRIVER_MAGIC,
  537. tty->major = GIG_MAJOR,
  538. tty->type = TTY_DRIVER_TYPE_SERIAL,
  539. tty->subtype = SERIAL_TYPE_NORMAL,
  540. tty->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
  541. tty->driver_name = procname;
  542. tty->name = devname;
  543. tty->minor_start = drv->minor;
  544. tty->num = drv->minors;
  545. tty->owner = THIS_MODULE;
  546. tty->init_termios = tty_std_termios; //FIXME
  547. tty->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; //FIXME
  548. tty_set_operations(tty, &if_ops);
  549. ret = tty_register_driver(tty);
  550. if (ret < 0) {
  551. pr_err("error %d registering tty driver\n", ret);
  552. goto error;
  553. }
  554. gig_dbg(DEBUG_IF, "tty driver initialized");
  555. drv->have_tty = 1;
  556. return;
  557. enomem:
  558. pr_err("out of memory\n");
  559. error:
  560. if (drv->tty)
  561. put_tty_driver(drv->tty);
  562. }
  563. void gigaset_if_freedriver(struct gigaset_driver *drv)
  564. {
  565. if (!drv->have_tty)
  566. return;
  567. drv->have_tty = 0;
  568. tty_unregister_driver(drv->tty);
  569. put_tty_driver(drv->tty);
  570. }