Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 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 | * ===================================================================== |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 12 | */ |
| 13 | |
| 14 | #include "gigaset.h" |
| 15 | #include <linux/gigaset_dev.h> |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 16 | #include <linux/tty_flip.h> |
Paul Gortmaker | 07a97fe | 2011-08-30 12:08:51 -0400 | [diff] [blame] | 17 | #include <linux/module.h> |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 18 | |
| 19 | /*** our ioctls ***/ |
| 20 | |
| 21 | static int if_lock(struct cardstate *cs, int *arg) |
| 22 | { |
| 23 | int cmd = *arg; |
| 24 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 25 | gig_dbg(DEBUG_IF, "%u: if_lock (%d)", cs->minor_index, cmd); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 26 | |
| 27 | if (cmd > 1) |
| 28 | return -EINVAL; |
| 29 | |
| 30 | if (cmd < 0) { |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 31 | *arg = cs->mstate == MS_LOCKED; |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 32 | return 0; |
| 33 | } |
| 34 | |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 35 | if (!cmd && cs->mstate == MS_LOCKED && cs->connected) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 36 | cs->ops->set_modem_ctrl(cs, 0, TIOCM_DTR | TIOCM_RTS); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 37 | cs->ops->baud_rate(cs, B115200); |
| 38 | cs->ops->set_line_ctrl(cs, CS8); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 39 | cs->control_state = TIOCM_DTR | TIOCM_RTS; |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | cs->waiting = 1; |
| 43 | if (!gigaset_add_event(cs, &cs->at_state, EV_IF_LOCK, |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 44 | NULL, cmd, NULL)) { |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 45 | cs->waiting = 0; |
| 46 | return -ENOMEM; |
| 47 | } |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 48 | gigaset_schedule_event(cs); |
| 49 | |
| 50 | wait_event(cs->waitqueue, !cs->waiting); |
| 51 | |
| 52 | if (cs->cmd_result >= 0) { |
| 53 | *arg = cs->cmd_result; |
| 54 | return 0; |
| 55 | } |
| 56 | |
| 57 | return cs->cmd_result; |
| 58 | } |
| 59 | |
| 60 | static int if_version(struct cardstate *cs, unsigned arg[4]) |
| 61 | { |
| 62 | static const unsigned version[4] = GIG_VERSION; |
| 63 | static const unsigned compat[4] = GIG_COMPAT; |
| 64 | unsigned cmd = arg[0]; |
| 65 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 66 | gig_dbg(DEBUG_IF, "%u: if_version (%d)", cs->minor_index, cmd); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 67 | |
| 68 | switch (cmd) { |
| 69 | case GIGVER_DRIVER: |
| 70 | memcpy(arg, version, sizeof version); |
| 71 | return 0; |
| 72 | case GIGVER_COMPAT: |
| 73 | memcpy(arg, compat, sizeof compat); |
| 74 | return 0; |
| 75 | case GIGVER_FWBASE: |
| 76 | cs->waiting = 1; |
| 77 | if (!gigaset_add_event(cs, &cs->at_state, EV_IF_VER, |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 78 | NULL, 0, arg)) { |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 79 | cs->waiting = 0; |
| 80 | return -ENOMEM; |
| 81 | } |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 82 | gigaset_schedule_event(cs); |
| 83 | |
| 84 | wait_event(cs->waitqueue, !cs->waiting); |
| 85 | |
| 86 | if (cs->cmd_result >= 0) |
| 87 | return 0; |
| 88 | |
| 89 | return cs->cmd_result; |
| 90 | default: |
| 91 | return -EINVAL; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | static int if_config(struct cardstate *cs, int *arg) |
| 96 | { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 97 | gig_dbg(DEBUG_IF, "%u: if_config (%d)", cs->minor_index, *arg); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 98 | |
| 99 | if (*arg != 1) |
| 100 | return -EINVAL; |
| 101 | |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 102 | if (cs->mstate != MS_LOCKED) |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 103 | return -EBUSY; |
| 104 | |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 105 | if (!cs->connected) { |
Tilman Schmidt | c8770dc | 2008-12-26 01:21:29 -0800 | [diff] [blame] | 106 | pr_err("%s: not connected\n", __func__); |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 107 | return -ENODEV; |
| 108 | } |
| 109 | |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 110 | *arg = 0; |
| 111 | return gigaset_enterconfigmode(cs); |
| 112 | } |
| 113 | |
| 114 | /*** the terminal driver ***/ |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 115 | |
| 116 | static int if_open(struct tty_struct *tty, struct file *filp) |
| 117 | { |
| 118 | struct cardstate *cs; |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 119 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 120 | gig_dbg(DEBUG_IF, "%d+%d: %s()", |
| 121 | tty->driver->minor_start, tty->index, __func__); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 122 | |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 123 | cs = gigaset_get_cs_by_tty(tty); |
Tilman Schmidt | e468c04 | 2008-02-06 01:38:29 -0800 | [diff] [blame] | 124 | if (!cs || !try_module_get(cs->driver->owner)) |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 125 | return -ENODEV; |
| 126 | |
Pavel Shved | 2f9381e | 2011-06-17 06:25:11 +0000 | [diff] [blame] | 127 | if (mutex_lock_interruptible(&cs->mutex)) { |
| 128 | module_put(cs->driver->owner); |
Tilman Schmidt | d9ba9c9 | 2009-10-25 09:30:17 +0000 | [diff] [blame] | 129 | return -ERESTARTSYS; |
Pavel Shved | 2f9381e | 2011-06-17 06:25:11 +0000 | [diff] [blame] | 130 | } |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 131 | tty->driver_data = cs; |
| 132 | |
Jiri Slaby | 48a7466 | 2012-03-05 14:52:55 +0100 | [diff] [blame] | 133 | ++cs->port.count; |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 134 | |
Jiri Slaby | 48a7466 | 2012-03-05 14:52:55 +0100 | [diff] [blame] | 135 | if (cs->port.count == 1) { |
| 136 | tty_port_tty_set(&cs->port, tty); |
Jiri Slaby | d6c53c0 | 2013-01-03 15:53:05 +0100 | [diff] [blame] | 137 | cs->port.low_latency = 1; |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 138 | } |
| 139 | |
Tilman Schmidt | abfd1dc | 2006-04-10 22:55:12 -0700 | [diff] [blame] | 140 | mutex_unlock(&cs->mutex); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 141 | return 0; |
| 142 | } |
| 143 | |
| 144 | static void if_close(struct tty_struct *tty, struct file *filp) |
| 145 | { |
Jiri Slaby | fc258f8 | 2012-03-05 14:52:54 +0100 | [diff] [blame] | 146 | struct cardstate *cs = tty->driver_data; |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 147 | |
Jiri Slaby | fc258f8 | 2012-03-05 14:52:54 +0100 | [diff] [blame] | 148 | if (!cs) { /* happens if we didn't find cs in open */ |
Tilman Schmidt | ef37ea3 | 2012-03-25 19:12:37 +0200 | [diff] [blame] | 149 | gig_dbg(DEBUG_IF, "%s: no cardstate", __func__); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 150 | return; |
| 151 | } |
| 152 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 153 | gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 154 | |
Tilman Schmidt | abfd1dc | 2006-04-10 22:55:12 -0700 | [diff] [blame] | 155 | mutex_lock(&cs->mutex); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 156 | |
Tilman Schmidt | 51370e5 | 2009-04-05 06:39:33 +0000 | [diff] [blame] | 157 | if (!cs->connected) |
| 158 | gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */ |
Jiri Slaby | 48a7466 | 2012-03-05 14:52:55 +0100 | [diff] [blame] | 159 | else if (!cs->port.count) |
Tilman Schmidt | 5002779 | 2008-07-23 21:28:27 -0700 | [diff] [blame] | 160 | dev_warn(cs->dev, "%s: device not opened\n", __func__); |
Jiri Slaby | 48a7466 | 2012-03-05 14:52:55 +0100 | [diff] [blame] | 161 | else if (!--cs->port.count) |
| 162 | tty_port_tty_set(&cs->port, NULL); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 163 | |
Tilman Schmidt | abfd1dc | 2006-04-10 22:55:12 -0700 | [diff] [blame] | 164 | mutex_unlock(&cs->mutex); |
Tilman Schmidt | e468c04 | 2008-02-06 01:38:29 -0800 | [diff] [blame] | 165 | |
| 166 | module_put(cs->driver->owner); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 167 | } |
| 168 | |
Alan Cox | 6caa76b | 2011-02-14 16:27:22 +0000 | [diff] [blame] | 169 | static int if_ioctl(struct tty_struct *tty, |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 170 | unsigned int cmd, unsigned long arg) |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 171 | { |
Jiri Slaby | fc258f8 | 2012-03-05 14:52:54 +0100 | [diff] [blame] | 172 | struct cardstate *cs = tty->driver_data; |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 173 | int retval = -ENODEV; |
| 174 | int int_arg; |
| 175 | unsigned char buf[6]; |
| 176 | unsigned version[4]; |
| 177 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 178 | gig_dbg(DEBUG_IF, "%u: %s(0x%x)", cs->minor_index, __func__, cmd); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 179 | |
Tilman Schmidt | abfd1dc | 2006-04-10 22:55:12 -0700 | [diff] [blame] | 180 | if (mutex_lock_interruptible(&cs->mutex)) |
Tilman Schmidt | d9ba9c9 | 2009-10-25 09:30:17 +0000 | [diff] [blame] | 181 | return -ERESTARTSYS; |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 182 | |
Tilman Schmidt | 51370e5 | 2009-04-05 06:39:33 +0000 | [diff] [blame] | 183 | if (!cs->connected) { |
| 184 | gig_dbg(DEBUG_IF, "not connected"); |
| 185 | retval = -ENODEV; |
Jiri Slaby | fc258f8 | 2012-03-05 14:52:54 +0100 | [diff] [blame] | 186 | } else { |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 187 | retval = 0; |
| 188 | switch (cmd) { |
| 189 | case GIGASET_REDIR: |
| 190 | retval = get_user(int_arg, (int __user *) arg); |
| 191 | if (retval >= 0) |
| 192 | retval = if_lock(cs, &int_arg); |
| 193 | if (retval >= 0) |
| 194 | retval = put_user(int_arg, (int __user *) arg); |
| 195 | break; |
| 196 | case GIGASET_CONFIG: |
| 197 | retval = get_user(int_arg, (int __user *) arg); |
| 198 | if (retval >= 0) |
| 199 | retval = if_config(cs, &int_arg); |
| 200 | if (retval >= 0) |
| 201 | retval = put_user(int_arg, (int __user *) arg); |
| 202 | break; |
| 203 | case GIGASET_BRKCHARS: |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 204 | retval = copy_from_user(&buf, |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 205 | (const unsigned char __user *) arg, 6) |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 206 | ? -EFAULT : 0; |
Tilman Schmidt | 0137150 | 2006-04-10 22:55:11 -0700 | [diff] [blame] | 207 | if (retval >= 0) { |
| 208 | gigaset_dbg_buffer(DEBUG_IF, "GIGASET_BRKCHARS", |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 209 | 6, (const unsigned char *) arg); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 210 | retval = cs->ops->brkchars(cs, buf); |
Tilman Schmidt | 0137150 | 2006-04-10 22:55:11 -0700 | [diff] [blame] | 211 | } |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 212 | break; |
| 213 | case GIGASET_VERSION: |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 214 | retval = copy_from_user(version, |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 215 | (unsigned __user *) arg, sizeof version) |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 216 | ? -EFAULT : 0; |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 217 | if (retval >= 0) |
| 218 | retval = if_version(cs, version); |
| 219 | if (retval >= 0) |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 220 | retval = copy_to_user((unsigned __user *) arg, |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 221 | version, sizeof version) |
| 222 | ? -EFAULT : 0; |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 223 | break; |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 224 | default: |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 225 | gig_dbg(DEBUG_IF, "%s: arg not supported - 0x%04x", |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 226 | __func__, cmd); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 227 | retval = -ENOIOCTLCMD; |
| 228 | } |
| 229 | } |
| 230 | |
Tilman Schmidt | abfd1dc | 2006-04-10 22:55:12 -0700 | [diff] [blame] | 231 | mutex_unlock(&cs->mutex); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 232 | |
| 233 | return retval; |
| 234 | } |
| 235 | |
Alan Cox | 60b33c1 | 2011-02-14 16:26:14 +0000 | [diff] [blame] | 236 | static int if_tiocmget(struct tty_struct *tty) |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 237 | { |
Jiri Slaby | fc258f8 | 2012-03-05 14:52:54 +0100 | [diff] [blame] | 238 | struct cardstate *cs = tty->driver_data; |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 239 | int retval; |
| 240 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 241 | gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 242 | |
Tilman Schmidt | abfd1dc | 2006-04-10 22:55:12 -0700 | [diff] [blame] | 243 | if (mutex_lock_interruptible(&cs->mutex)) |
Tilman Schmidt | d9ba9c9 | 2009-10-25 09:30:17 +0000 | [diff] [blame] | 244 | return -ERESTARTSYS; |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 245 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 246 | retval = cs->control_state & (TIOCM_RTS | TIOCM_DTR); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 247 | |
Tilman Schmidt | abfd1dc | 2006-04-10 22:55:12 -0700 | [diff] [blame] | 248 | mutex_unlock(&cs->mutex); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 249 | |
| 250 | return retval; |
| 251 | } |
| 252 | |
Alan Cox | 20b9d17 | 2011-02-14 16:26:50 +0000 | [diff] [blame] | 253 | static int if_tiocmset(struct tty_struct *tty, |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 254 | unsigned int set, unsigned int clear) |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 255 | { |
Jiri Slaby | fc258f8 | 2012-03-05 14:52:54 +0100 | [diff] [blame] | 256 | struct cardstate *cs = tty->driver_data; |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 257 | int retval; |
| 258 | unsigned mc; |
| 259 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 260 | gig_dbg(DEBUG_IF, "%u: %s(0x%x, 0x%x)", |
| 261 | cs->minor_index, __func__, set, clear); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 262 | |
Tilman Schmidt | abfd1dc | 2006-04-10 22:55:12 -0700 | [diff] [blame] | 263 | if (mutex_lock_interruptible(&cs->mutex)) |
Tilman Schmidt | d9ba9c9 | 2009-10-25 09:30:17 +0000 | [diff] [blame] | 264 | return -ERESTARTSYS; |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 265 | |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 266 | if (!cs->connected) { |
Tilman Schmidt | 51370e5 | 2009-04-05 06:39:33 +0000 | [diff] [blame] | 267 | gig_dbg(DEBUG_IF, "not connected"); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 268 | retval = -ENODEV; |
| 269 | } else { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 270 | mc = (cs->control_state | set) & ~clear & (TIOCM_RTS | TIOCM_DTR); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 271 | retval = cs->ops->set_modem_ctrl(cs, cs->control_state, mc); |
| 272 | cs->control_state = mc; |
| 273 | } |
| 274 | |
Tilman Schmidt | abfd1dc | 2006-04-10 22:55:12 -0700 | [diff] [blame] | 275 | mutex_unlock(&cs->mutex); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 276 | |
| 277 | return retval; |
| 278 | } |
| 279 | |
| 280 | static int if_write(struct tty_struct *tty, const unsigned char *buf, int count) |
| 281 | { |
Jiri Slaby | fc258f8 | 2012-03-05 14:52:54 +0100 | [diff] [blame] | 282 | struct cardstate *cs = tty->driver_data; |
Tilman Schmidt | e3628dd | 2010-07-05 14:18:43 +0000 | [diff] [blame] | 283 | struct cmdbuf_t *cb; |
| 284 | int retval; |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 285 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 286 | gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 287 | |
Tilman Schmidt | abfd1dc | 2006-04-10 22:55:12 -0700 | [diff] [blame] | 288 | if (mutex_lock_interruptible(&cs->mutex)) |
Tilman Schmidt | d9ba9c9 | 2009-10-25 09:30:17 +0000 | [diff] [blame] | 289 | return -ERESTARTSYS; |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 290 | |
Tilman Schmidt | 51370e5 | 2009-04-05 06:39:33 +0000 | [diff] [blame] | 291 | if (!cs->connected) { |
| 292 | gig_dbg(DEBUG_IF, "not connected"); |
| 293 | retval = -ENODEV; |
Tilman Schmidt | e3628dd | 2010-07-05 14:18:43 +0000 | [diff] [blame] | 294 | goto done; |
| 295 | } |
Tilman Schmidt | e3628dd | 2010-07-05 14:18:43 +0000 | [diff] [blame] | 296 | if (cs->mstate != MS_LOCKED) { |
Tilman Schmidt | 5002779 | 2008-07-23 21:28:27 -0700 | [diff] [blame] | 297 | dev_warn(cs->dev, "can't write to unlocked device\n"); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 298 | retval = -EBUSY; |
Tilman Schmidt | e3628dd | 2010-07-05 14:18:43 +0000 | [diff] [blame] | 299 | goto done; |
| 300 | } |
| 301 | if (count <= 0) { |
| 302 | /* nothing to do */ |
| 303 | retval = 0; |
| 304 | goto done; |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 305 | } |
| 306 | |
Tilman Schmidt | e3628dd | 2010-07-05 14:18:43 +0000 | [diff] [blame] | 307 | cb = kmalloc(sizeof(struct cmdbuf_t) + count, GFP_KERNEL); |
| 308 | if (!cb) { |
| 309 | dev_err(cs->dev, "%s: out of memory\n", __func__); |
| 310 | retval = -ENOMEM; |
| 311 | goto done; |
| 312 | } |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 313 | |
Tilman Schmidt | e3628dd | 2010-07-05 14:18:43 +0000 | [diff] [blame] | 314 | memcpy(cb->buf, buf, count); |
| 315 | cb->len = count; |
| 316 | cb->offset = 0; |
| 317 | cb->next = NULL; |
| 318 | cb->wake_tasklet = &cs->if_wake_tasklet; |
| 319 | retval = cs->ops->write_cmd(cs, cb); |
| 320 | done: |
| 321 | mutex_unlock(&cs->mutex); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 322 | return retval; |
| 323 | } |
| 324 | |
| 325 | static int if_write_room(struct tty_struct *tty) |
| 326 | { |
Jiri Slaby | fc258f8 | 2012-03-05 14:52:54 +0100 | [diff] [blame] | 327 | struct cardstate *cs = tty->driver_data; |
Tilman Schmidt | cdc4827 | 2013-01-21 11:57:20 +0000 | [diff] [blame] | 328 | int retval; |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 329 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 330 | gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 331 | |
Tilman Schmidt | abfd1dc | 2006-04-10 22:55:12 -0700 | [diff] [blame] | 332 | if (mutex_lock_interruptible(&cs->mutex)) |
Tilman Schmidt | d9ba9c9 | 2009-10-25 09:30:17 +0000 | [diff] [blame] | 333 | return -ERESTARTSYS; |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 334 | |
Tilman Schmidt | 51370e5 | 2009-04-05 06:39:33 +0000 | [diff] [blame] | 335 | if (!cs->connected) { |
| 336 | gig_dbg(DEBUG_IF, "not connected"); |
| 337 | retval = -ENODEV; |
Jiri Slaby | fc258f8 | 2012-03-05 14:52:54 +0100 | [diff] [blame] | 338 | } else if (cs->mstate != MS_LOCKED) { |
Tilman Schmidt | 5002779 | 2008-07-23 21:28:27 -0700 | [diff] [blame] | 339 | dev_warn(cs->dev, "can't write to unlocked device\n"); |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 340 | retval = -EBUSY; |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 341 | } else |
| 342 | retval = cs->ops->write_room(cs); |
| 343 | |
Tilman Schmidt | abfd1dc | 2006-04-10 22:55:12 -0700 | [diff] [blame] | 344 | mutex_unlock(&cs->mutex); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 345 | |
| 346 | return retval; |
| 347 | } |
| 348 | |
| 349 | static int if_chars_in_buffer(struct tty_struct *tty) |
| 350 | { |
Jiri Slaby | fc258f8 | 2012-03-05 14:52:54 +0100 | [diff] [blame] | 351 | struct cardstate *cs = tty->driver_data; |
Tilman Schmidt | a4304f2 | 2009-08-06 20:33:33 -0700 | [diff] [blame] | 352 | int retval = 0; |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 353 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 354 | gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 355 | |
Tilman Schmidt | a4304f2 | 2009-08-06 20:33:33 -0700 | [diff] [blame] | 356 | mutex_lock(&cs->mutex); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 357 | |
Tilman Schmidt | a4304f2 | 2009-08-06 20:33:33 -0700 | [diff] [blame] | 358 | if (!cs->connected) |
Tilman Schmidt | 51370e5 | 2009-04-05 06:39:33 +0000 | [diff] [blame] | 359 | gig_dbg(DEBUG_IF, "not connected"); |
Tilman Schmidt | a4304f2 | 2009-08-06 20:33:33 -0700 | [diff] [blame] | 360 | else if (cs->mstate != MS_LOCKED) |
Tilman Schmidt | 5002779 | 2008-07-23 21:28:27 -0700 | [diff] [blame] | 361 | dev_warn(cs->dev, "can't write to unlocked device\n"); |
Tilman Schmidt | a4304f2 | 2009-08-06 20:33:33 -0700 | [diff] [blame] | 362 | else |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 363 | retval = cs->ops->chars_in_buffer(cs); |
| 364 | |
Tilman Schmidt | abfd1dc | 2006-04-10 22:55:12 -0700 | [diff] [blame] | 365 | mutex_unlock(&cs->mutex); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 366 | |
| 367 | return retval; |
| 368 | } |
| 369 | |
| 370 | static void if_throttle(struct tty_struct *tty) |
| 371 | { |
Jiri Slaby | fc258f8 | 2012-03-05 14:52:54 +0100 | [diff] [blame] | 372 | struct cardstate *cs = tty->driver_data; |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 373 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 374 | gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 375 | |
Tilman Schmidt | abfd1dc | 2006-04-10 22:55:12 -0700 | [diff] [blame] | 376 | mutex_lock(&cs->mutex); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 377 | |
Tilman Schmidt | 51370e5 | 2009-04-05 06:39:33 +0000 | [diff] [blame] | 378 | if (!cs->connected) |
| 379 | gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */ |
Tilman Schmidt | d9ba9c9 | 2009-10-25 09:30:17 +0000 | [diff] [blame] | 380 | else |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 381 | gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 382 | |
Tilman Schmidt | abfd1dc | 2006-04-10 22:55:12 -0700 | [diff] [blame] | 383 | mutex_unlock(&cs->mutex); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | static void if_unthrottle(struct tty_struct *tty) |
| 387 | { |
Jiri Slaby | fc258f8 | 2012-03-05 14:52:54 +0100 | [diff] [blame] | 388 | struct cardstate *cs = tty->driver_data; |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 389 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 390 | gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 391 | |
Tilman Schmidt | abfd1dc | 2006-04-10 22:55:12 -0700 | [diff] [blame] | 392 | mutex_lock(&cs->mutex); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 393 | |
Tilman Schmidt | 51370e5 | 2009-04-05 06:39:33 +0000 | [diff] [blame] | 394 | if (!cs->connected) |
| 395 | gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */ |
Tilman Schmidt | d9ba9c9 | 2009-10-25 09:30:17 +0000 | [diff] [blame] | 396 | else |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 397 | gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 398 | |
Tilman Schmidt | abfd1dc | 2006-04-10 22:55:12 -0700 | [diff] [blame] | 399 | mutex_unlock(&cs->mutex); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 400 | } |
| 401 | |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 402 | static void if_set_termios(struct tty_struct *tty, struct ktermios *old) |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 403 | { |
Jiri Slaby | fc258f8 | 2012-03-05 14:52:54 +0100 | [diff] [blame] | 404 | struct cardstate *cs = tty->driver_data; |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 405 | unsigned int iflag; |
| 406 | unsigned int cflag; |
| 407 | unsigned int old_cflag; |
| 408 | unsigned int control_state, new_state; |
| 409 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 410 | gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 411 | |
Tilman Schmidt | abfd1dc | 2006-04-10 22:55:12 -0700 | [diff] [blame] | 412 | mutex_lock(&cs->mutex); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 413 | |
Tilman Schmidt | 51370e5 | 2009-04-05 06:39:33 +0000 | [diff] [blame] | 414 | if (!cs->connected) { |
| 415 | gig_dbg(DEBUG_IF, "not connected"); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 416 | goto out; |
| 417 | } |
| 418 | |
Alan Cox | adc8d74 | 2012-07-14 15:31:47 +0100 | [diff] [blame] | 419 | iflag = tty->termios.c_iflag; |
| 420 | cflag = tty->termios.c_cflag; |
Tilman Schmidt | d9ba9c9 | 2009-10-25 09:30:17 +0000 | [diff] [blame] | 421 | old_cflag = old ? old->c_cflag : cflag; |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 422 | gig_dbg(DEBUG_IF, "%u: iflag %x cflag %x old %x", |
| 423 | cs->minor_index, iflag, cflag, old_cflag); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 424 | |
| 425 | /* get a local copy of the current port settings */ |
| 426 | control_state = cs->control_state; |
| 427 | |
| 428 | /* |
| 429 | * Update baud rate. |
| 430 | * Do not attempt to cache old rates and skip settings, |
| 431 | * disconnects screw such tricks up completely. |
| 432 | * Premature optimization is the root of all evil. |
| 433 | */ |
| 434 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 435 | /* reassert DTR and (maybe) RTS on transition from B0 */ |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 436 | if ((old_cflag & CBAUD) == B0) { |
| 437 | new_state = control_state | TIOCM_DTR; |
| 438 | /* don't set RTS if using hardware flow control */ |
| 439 | if (!(old_cflag & CRTSCTS)) |
| 440 | new_state |= TIOCM_RTS; |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 441 | gig_dbg(DEBUG_IF, "%u: from B0 - set DTR%s", |
| 442 | cs->minor_index, |
| 443 | (new_state & TIOCM_RTS) ? " only" : "/RTS"); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 444 | cs->ops->set_modem_ctrl(cs, control_state, new_state); |
| 445 | control_state = new_state; |
| 446 | } |
| 447 | |
| 448 | cs->ops->baud_rate(cs, cflag & CBAUD); |
| 449 | |
| 450 | if ((cflag & CBAUD) == B0) { |
| 451 | /* Drop RTS and DTR */ |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 452 | gig_dbg(DEBUG_IF, "%u: to B0 - drop DTR/RTS", cs->minor_index); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 453 | new_state = control_state & ~(TIOCM_DTR | TIOCM_RTS); |
| 454 | cs->ops->set_modem_ctrl(cs, control_state, new_state); |
| 455 | control_state = new_state; |
| 456 | } |
| 457 | |
| 458 | /* |
| 459 | * Update line control register (LCR) |
| 460 | */ |
| 461 | |
| 462 | cs->ops->set_line_ctrl(cs, cflag); |
| 463 | |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 464 | /* save off the modified port settings */ |
| 465 | cs->control_state = control_state; |
| 466 | |
| 467 | out: |
Tilman Schmidt | abfd1dc | 2006-04-10 22:55:12 -0700 | [diff] [blame] | 468 | mutex_unlock(&cs->mutex); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 469 | } |
| 470 | |
Tilman Schmidt | cdc4827 | 2013-01-21 11:57:20 +0000 | [diff] [blame] | 471 | static const struct tty_operations if_ops = { |
| 472 | .open = if_open, |
| 473 | .close = if_close, |
| 474 | .ioctl = if_ioctl, |
| 475 | .write = if_write, |
| 476 | .write_room = if_write_room, |
| 477 | .chars_in_buffer = if_chars_in_buffer, |
| 478 | .set_termios = if_set_termios, |
| 479 | .throttle = if_throttle, |
| 480 | .unthrottle = if_unthrottle, |
| 481 | .tiocmget = if_tiocmget, |
| 482 | .tiocmset = if_tiocmset, |
| 483 | }; |
| 484 | |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 485 | |
| 486 | /* wakeup tasklet for the write operation */ |
| 487 | static void if_wake(unsigned long data) |
| 488 | { |
Jiri Slaby | 48a7466 | 2012-03-05 14:52:55 +0100 | [diff] [blame] | 489 | struct cardstate *cs = (struct cardstate *)data; |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 490 | |
Jiri Slaby | 6aad04f | 2013-03-07 13:12:29 +0100 | [diff] [blame] | 491 | tty_port_tty_wakeup(&cs->port); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | /*** interface to common ***/ |
| 495 | |
| 496 | void gigaset_if_init(struct cardstate *cs) |
| 497 | { |
| 498 | struct gigaset_driver *drv; |
| 499 | |
| 500 | drv = cs->driver; |
| 501 | if (!drv->have_tty) |
| 502 | return; |
| 503 | |
Joe Perches | 5452fee | 2009-11-19 09:55:53 +0000 | [diff] [blame] | 504 | tasklet_init(&cs->if_wake_tasklet, if_wake, (unsigned long) cs); |
Tilman Schmidt | 7435f50 | 2007-02-12 00:52:24 -0800 | [diff] [blame] | 505 | |
| 506 | mutex_lock(&cs->mutex); |
Jiri Slaby | 734cc17 | 2012-08-07 21:47:47 +0200 | [diff] [blame] | 507 | cs->tty_dev = tty_port_register_device(&cs->port, drv->tty, |
| 508 | cs->minor_index, NULL); |
Hansjoerg Lipp | 3dda4e3 | 2006-04-22 18:43:00 +0200 | [diff] [blame] | 509 | |
Greg Kroah-Hartman | 01107d3 | 2006-08-07 22:19:37 -0700 | [diff] [blame] | 510 | if (!IS_ERR(cs->tty_dev)) |
| 511 | dev_set_drvdata(cs->tty_dev, cs); |
Hansjoerg Lipp | 3dda4e3 | 2006-04-22 18:43:00 +0200 | [diff] [blame] | 512 | else { |
Tilman Schmidt | 42e3d61 | 2009-05-13 12:44:17 +0000 | [diff] [blame] | 513 | pr_warning("could not register device to the tty subsystem\n"); |
Greg Kroah-Hartman | 01107d3 | 2006-08-07 22:19:37 -0700 | [diff] [blame] | 514 | cs->tty_dev = NULL; |
Hansjoerg Lipp | 3dda4e3 | 2006-04-22 18:43:00 +0200 | [diff] [blame] | 515 | } |
Tilman Schmidt | 7435f50 | 2007-02-12 00:52:24 -0800 | [diff] [blame] | 516 | mutex_unlock(&cs->mutex); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | void gigaset_if_free(struct cardstate *cs) |
| 520 | { |
| 521 | struct gigaset_driver *drv; |
| 522 | |
| 523 | drv = cs->driver; |
| 524 | if (!drv->have_tty) |
| 525 | return; |
| 526 | |
| 527 | tasklet_disable(&cs->if_wake_tasklet); |
| 528 | tasklet_kill(&cs->if_wake_tasklet); |
Greg Kroah-Hartman | 01107d3 | 2006-08-07 22:19:37 -0700 | [diff] [blame] | 529 | cs->tty_dev = NULL; |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 530 | tty_unregister_device(drv->tty, cs->minor_index); |
| 531 | } |
| 532 | |
Tilman Schmidt | 1cec972 | 2009-10-06 12:19:01 +0000 | [diff] [blame] | 533 | /** |
| 534 | * gigaset_if_receive() - pass a received block of data to the tty device |
| 535 | * @cs: device descriptor structure. |
| 536 | * @buffer: received data. |
| 537 | * @len: number of bytes received. |
| 538 | * |
| 539 | * Called by asyncdata/isocdata if a block of data received from the |
| 540 | * device must be sent to userspace through the ttyG* device. |
| 541 | */ |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 542 | void gigaset_if_receive(struct cardstate *cs, |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 543 | unsigned char *buffer, size_t len) |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 544 | { |
Jiri Slaby | 05c7cd3 | 2013-01-03 15:53:04 +0100 | [diff] [blame] | 545 | tty_insert_flip_string(&cs->port, buffer, len); |
Jiri Slaby | 2e124b4 | 2013-01-03 15:53:06 +0100 | [diff] [blame] | 546 | tty_flip_buffer_push(&cs->port); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 547 | } |
| 548 | EXPORT_SYMBOL_GPL(gigaset_if_receive); |
| 549 | |
| 550 | /* gigaset_if_initdriver |
| 551 | * Initialize tty interface. |
| 552 | * parameters: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 553 | * drv Driver |
| 554 | * procname Name of the driver (e.g. for /proc/tty/drivers) |
| 555 | * devname Name of the device files (prefix without minor number) |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 556 | */ |
| 557 | void gigaset_if_initdriver(struct gigaset_driver *drv, const char *procname, |
Greg Kroah-Hartman | f4eaa37 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 558 | const char *devname) |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 559 | { |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 560 | int ret; |
| 561 | struct tty_driver *tty; |
| 562 | |
| 563 | drv->have_tty = 0; |
| 564 | |
Jiri Slaby | 2f16669 | 2012-03-05 14:51:52 +0100 | [diff] [blame] | 565 | drv->tty = tty = alloc_tty_driver(drv->minors); |
Tilman Schmidt | d9ba9c9 | 2009-10-25 09:30:17 +0000 | [diff] [blame] | 566 | if (tty == NULL) |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 567 | goto enomem; |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 568 | |
Joe Perches | 5bd4973 | 2012-02-27 14:12:07 -0500 | [diff] [blame] | 569 | tty->type = TTY_DRIVER_TYPE_SERIAL; |
| 570 | tty->subtype = SERIAL_TYPE_NORMAL; |
Greg Kroah-Hartman | 331b831 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 571 | tty->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 572 | |
| 573 | tty->driver_name = procname; |
| 574 | tty->name = devname; |
| 575 | tty->minor_start = drv->minor; |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 576 | |
Tilman Schmidt | d9ba9c9 | 2009-10-25 09:30:17 +0000 | [diff] [blame] | 577 | tty->init_termios = tty_std_termios; |
| 578 | tty->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 579 | tty_set_operations(tty, &if_ops); |
| 580 | |
| 581 | ret = tty_register_driver(tty); |
| 582 | if (ret < 0) { |
Tilman Schmidt | c8770dc | 2008-12-26 01:21:29 -0800 | [diff] [blame] | 583 | pr_err("error %d registering tty driver\n", ret); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 584 | goto error; |
| 585 | } |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 586 | gig_dbg(DEBUG_IF, "tty driver initialized"); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 587 | drv->have_tty = 1; |
| 588 | return; |
| 589 | |
| 590 | enomem: |
Tilman Schmidt | c8770dc | 2008-12-26 01:21:29 -0800 | [diff] [blame] | 591 | pr_err("out of memory\n"); |
Hansjoerg Lipp | ee8a4b7 | 2006-03-26 01:38:32 -0800 | [diff] [blame] | 592 | error: |
| 593 | if (drv->tty) |
| 594 | put_tty_driver(drv->tty); |
| 595 | } |
| 596 | |
| 597 | void gigaset_if_freedriver(struct gigaset_driver *drv) |
| 598 | { |
| 599 | if (!drv->have_tty) |
| 600 | return; |
| 601 | |
| 602 | drv->have_tty = 0; |
| 603 | tty_unregister_driver(drv->tty); |
| 604 | put_tty_driver(drv->tty); |
| 605 | } |