interface.c 17 KB

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