diff options
author | Alan Cox <alan@lxorguk.ukuu.org.uk> | 2008-04-30 03:54:13 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-04-30 11:29:47 -0400 |
commit | f34d7a5b7010b82fe97da95496b9971435530062 (patch) | |
tree | 87e2abec1e33ed4fe5e63ee2fd000bc2ad745e57 /drivers/net/irda/irtty-sir.c | |
parent | 251b8dd7eee30fda089a1dc088abf4fc9a0dee9c (diff) |
tty: The big operations rework
- Operations are now a shared const function block as with most other Linux
objects
- Introduce wrappers for some optional functions to get consistent behaviour
- Wrap put_char which used to be patched by the tty layer
- Document which functions are needed/optional
- Make put_char report success/fail
- Cache the driver->ops pointer in the tty as tty->ops
- Remove various surplus lock calls we no longer need
- Remove proc_write method as noted by Alexey Dobriyan
- Introduce some missing sanity checks where certain driver/ldisc
combinations would oops as they didn't check needed methods were present
[akpm@linux-foundation.org: fix fs/compat_ioctl.c build]
[akpm@linux-foundation.org: fix isicom]
[akpm@linux-foundation.org: fix arch/ia64/hp/sim/simserial.c build]
[akpm@linux-foundation.org: fix kgdb]
Signed-off-by: Alan Cox <alan@redhat.com>
Acked-by: Greg Kroah-Hartman <gregkh@suse.de>
Cc: Jason Wessel <jason.wessel@windriver.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/net/irda/irtty-sir.c')
-rw-r--r-- | drivers/net/irda/irtty-sir.c | 95 |
1 files changed, 27 insertions, 68 deletions
diff --git a/drivers/net/irda/irtty-sir.c b/drivers/net/irda/irtty-sir.c index fc753d7f674e..e6f40b7f9041 100644 --- a/drivers/net/irda/irtty-sir.c +++ b/drivers/net/irda/irtty-sir.c | |||
@@ -64,7 +64,7 @@ static int irtty_chars_in_buffer(struct sir_dev *dev) | |||
64 | IRDA_ASSERT(priv != NULL, return -1;); | 64 | IRDA_ASSERT(priv != NULL, return -1;); |
65 | IRDA_ASSERT(priv->magic == IRTTY_MAGIC, return -1;); | 65 | IRDA_ASSERT(priv->magic == IRTTY_MAGIC, return -1;); |
66 | 66 | ||
67 | return priv->tty->driver->chars_in_buffer(priv->tty); | 67 | return tty_chars_in_buffer(priv->tty); |
68 | } | 68 | } |
69 | 69 | ||
70 | /* Wait (sleep) until underlaying hardware finished transmission | 70 | /* Wait (sleep) until underlaying hardware finished transmission |
@@ -93,10 +93,8 @@ static void irtty_wait_until_sent(struct sir_dev *dev) | |||
93 | IRDA_ASSERT(priv->magic == IRTTY_MAGIC, return;); | 93 | IRDA_ASSERT(priv->magic == IRTTY_MAGIC, return;); |
94 | 94 | ||
95 | tty = priv->tty; | 95 | tty = priv->tty; |
96 | if (tty->driver->wait_until_sent) { | 96 | if (tty->ops->wait_until_sent) { |
97 | lock_kernel(); | 97 | tty->ops->wait_until_sent(tty, msecs_to_jiffies(100)); |
98 | tty->driver->wait_until_sent(tty, msecs_to_jiffies(100)); | ||
99 | unlock_kernel(); | ||
100 | } | 98 | } |
101 | else { | 99 | else { |
102 | msleep(USBSERIAL_TX_DONE_DELAY); | 100 | msleep(USBSERIAL_TX_DONE_DELAY); |
@@ -125,48 +123,14 @@ static int irtty_change_speed(struct sir_dev *dev, unsigned speed) | |||
125 | 123 | ||
126 | tty = priv->tty; | 124 | tty = priv->tty; |
127 | 125 | ||
128 | lock_kernel(); | 126 | mutex_lock(&tty->termios_mutex); |
129 | old_termios = *(tty->termios); | 127 | old_termios = *(tty->termios); |
130 | cflag = tty->termios->c_cflag; | 128 | cflag = tty->termios->c_cflag; |
131 | 129 | tty_encode_baud_rate(tty, speed, speed); | |
132 | cflag &= ~CBAUD; | 130 | if (tty->ops->set_termios) |
133 | 131 | tty->ops->set_termios(tty, &old_termios); | |
134 | IRDA_DEBUG(2, "%s(), Setting speed to %d\n", __FUNCTION__, speed); | ||
135 | |||
136 | switch (speed) { | ||
137 | case 1200: | ||
138 | cflag |= B1200; | ||
139 | break; | ||
140 | case 2400: | ||
141 | cflag |= B2400; | ||
142 | break; | ||
143 | case 4800: | ||
144 | cflag |= B4800; | ||
145 | break; | ||
146 | case 19200: | ||
147 | cflag |= B19200; | ||
148 | break; | ||
149 | case 38400: | ||
150 | cflag |= B38400; | ||
151 | break; | ||
152 | case 57600: | ||
153 | cflag |= B57600; | ||
154 | break; | ||
155 | case 115200: | ||
156 | cflag |= B115200; | ||
157 | break; | ||
158 | case 9600: | ||
159 | default: | ||
160 | cflag |= B9600; | ||
161 | break; | ||
162 | } | ||
163 | |||
164 | tty->termios->c_cflag = cflag; | ||
165 | if (tty->driver->set_termios) | ||
166 | tty->driver->set_termios(tty, &old_termios); | ||
167 | unlock_kernel(); | ||
168 | |||
169 | priv->io.speed = speed; | 132 | priv->io.speed = speed; |
133 | mutex_unlock(&tty->termios_mutex); | ||
170 | 134 | ||
171 | return 0; | 135 | return 0; |
172 | } | 136 | } |
@@ -202,8 +166,8 @@ static int irtty_set_dtr_rts(struct sir_dev *dev, int dtr, int rts) | |||
202 | * This function is not yet defined for all tty driver, so | 166 | * This function is not yet defined for all tty driver, so |
203 | * let's be careful... Jean II | 167 | * let's be careful... Jean II |
204 | */ | 168 | */ |
205 | IRDA_ASSERT(priv->tty->driver->tiocmset != NULL, return -1;); | 169 | IRDA_ASSERT(priv->tty->ops->tiocmset != NULL, return -1;); |
206 | priv->tty->driver->tiocmset(priv->tty, NULL, set, clear); | 170 | priv->tty->ops->tiocmset(priv->tty, NULL, set, clear); |
207 | 171 | ||
208 | return 0; | 172 | return 0; |
209 | } | 173 | } |
@@ -225,17 +189,13 @@ static int irtty_do_write(struct sir_dev *dev, const unsigned char *ptr, size_t | |||
225 | IRDA_ASSERT(priv->magic == IRTTY_MAGIC, return -1;); | 189 | IRDA_ASSERT(priv->magic == IRTTY_MAGIC, return -1;); |
226 | 190 | ||
227 | tty = priv->tty; | 191 | tty = priv->tty; |
228 | if (!tty->driver->write) | 192 | if (!tty->ops->write) |
229 | return 0; | 193 | return 0; |
230 | tty->flags |= (1 << TTY_DO_WRITE_WAKEUP); | 194 | tty->flags |= (1 << TTY_DO_WRITE_WAKEUP); |
231 | if (tty->driver->write_room) { | 195 | writelen = tty_write_room(tty); |
232 | writelen = tty->driver->write_room(tty); | 196 | if (writelen > len) |
233 | if (writelen > len) | ||
234 | writelen = len; | ||
235 | } | ||
236 | else | ||
237 | writelen = len; | 197 | writelen = len; |
238 | return tty->driver->write(tty, ptr, writelen); | 198 | return tty->ops->write(tty, ptr, writelen); |
239 | } | 199 | } |
240 | 200 | ||
241 | /* ------------------------------------------------------- */ | 201 | /* ------------------------------------------------------- */ |
@@ -321,7 +281,7 @@ static inline void irtty_stop_receiver(struct tty_struct *tty, int stop) | |||
321 | struct ktermios old_termios; | 281 | struct ktermios old_termios; |
322 | int cflag; | 282 | int cflag; |
323 | 283 | ||
324 | lock_kernel(); | 284 | mutex_lock(&tty->termios_mutex); |
325 | old_termios = *(tty->termios); | 285 | old_termios = *(tty->termios); |
326 | cflag = tty->termios->c_cflag; | 286 | cflag = tty->termios->c_cflag; |
327 | 287 | ||
@@ -331,9 +291,9 @@ static inline void irtty_stop_receiver(struct tty_struct *tty, int stop) | |||
331 | cflag |= CREAD; | 291 | cflag |= CREAD; |
332 | 292 | ||
333 | tty->termios->c_cflag = cflag; | 293 | tty->termios->c_cflag = cflag; |
334 | if (tty->driver->set_termios) | 294 | if (tty->ops->set_termios) |
335 | tty->driver->set_termios(tty, &old_termios); | 295 | tty->ops->set_termios(tty, &old_termios); |
336 | unlock_kernel(); | 296 | mutex_unlock(&tty->termios_mutex); |
337 | } | 297 | } |
338 | 298 | ||
339 | /*****************************************************************/ | 299 | /*****************************************************************/ |
@@ -359,8 +319,8 @@ static int irtty_start_dev(struct sir_dev *dev) | |||
359 | 319 | ||
360 | tty = priv->tty; | 320 | tty = priv->tty; |
361 | 321 | ||
362 | if (tty->driver->start) | 322 | if (tty->ops->start) |
363 | tty->driver->start(tty); | 323 | tty->ops->start(tty); |
364 | /* Make sure we can receive more data */ | 324 | /* Make sure we can receive more data */ |
365 | irtty_stop_receiver(tty, FALSE); | 325 | irtty_stop_receiver(tty, FALSE); |
366 | 326 | ||
@@ -388,8 +348,8 @@ static int irtty_stop_dev(struct sir_dev *dev) | |||
388 | 348 | ||
389 | /* Make sure we don't receive more data */ | 349 | /* Make sure we don't receive more data */ |
390 | irtty_stop_receiver(tty, TRUE); | 350 | irtty_stop_receiver(tty, TRUE); |
391 | if (tty->driver->stop) | 351 | if (tty->ops->stop) |
392 | tty->driver->stop(tty); | 352 | tty->ops->stop(tty); |
393 | 353 | ||
394 | mutex_unlock(&irtty_mutex); | 354 | mutex_unlock(&irtty_mutex); |
395 | 355 | ||
@@ -483,11 +443,10 @@ static int irtty_open(struct tty_struct *tty) | |||
483 | 443 | ||
484 | /* stop the underlying driver */ | 444 | /* stop the underlying driver */ |
485 | irtty_stop_receiver(tty, TRUE); | 445 | irtty_stop_receiver(tty, TRUE); |
486 | if (tty->driver->stop) | 446 | if (tty->ops->stop) |
487 | tty->driver->stop(tty); | 447 | tty->ops->stop(tty); |
488 | 448 | ||
489 | if (tty->driver->flush_buffer) | 449 | tty_driver_flush_buffer(tty); |
490 | tty->driver->flush_buffer(tty); | ||
491 | 450 | ||
492 | /* apply mtt override */ | 451 | /* apply mtt override */ |
493 | sir_tty_drv.qos_mtt_bits = qos_mtt_bits; | 452 | sir_tty_drv.qos_mtt_bits = qos_mtt_bits; |
@@ -564,8 +523,8 @@ static void irtty_close(struct tty_struct *tty) | |||
564 | /* Stop tty */ | 523 | /* Stop tty */ |
565 | irtty_stop_receiver(tty, TRUE); | 524 | irtty_stop_receiver(tty, TRUE); |
566 | tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP); | 525 | tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP); |
567 | if (tty->driver->stop) | 526 | if (tty->ops->stop) |
568 | tty->driver->stop(tty); | 527 | tty->ops->stop(tty); |
569 | 528 | ||
570 | kfree(priv); | 529 | kfree(priv); |
571 | 530 | ||