Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tty: Use the generic RS485 ioctl on CRIS

Use the new general RS485 Linux data structure (introduced by Alan with
commit number c26c56c0f40e200e61d1390629c806f6adaffbcc) in the Cris
architecture too (currently, Cris still uses the old private data
structure instead of the new one).

Signed-off-by: Claudio Scordino <claudio@evidence.eu.com>
Tested-by: Hinko Kocevar <hinko.kocevar@cetrtapot.si>
Tested-by: Janez Cufer <janez.cufer@cetrtapot.si>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Alan Cox <alan@lxorguk.ukuu.org.uk>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Claudio Scordino and committed by
Linus Torvalds
6fd1af4c f786ddd2

+66 -29
+3 -2
arch/cris/include/asm/ioctls.h
··· 74 74 #define TIOCSHAYESESP 0x545F /* Set Hayes ESP configuration */ 75 75 #define FIOQSIZE 0x5460 76 76 77 - #define TIOCSERSETRS485 0x5461 /* enable rs-485 */ 78 - #define TIOCSERWRRS485 0x5462 /* write rs-485 */ 77 + #define TIOCSERSETRS485 0x5461 /* enable rs-485 (deprecated) */ 78 + #define TIOCSERWRRS485 0x5462 /* write rs-485 */ 79 + #define TIOCSRS485 0x5463 /* enable rs-485 */ 79 80 80 81 /* Used for packet mode */ 81 82 #define TIOCPKT_DATA 0
+3 -5
arch/cris/include/asm/rs485.h
··· 1 1 /* RS-485 structures */ 2 2 3 - /* RS-485 support */ 4 - /* Used with ioctl() TIOCSERSETRS485 */ 3 + /* Used with ioctl() TIOCSERSETRS485 for backward compatibility! 4 + * XXX: Do not use it for new code! 5 + */ 5 6 struct rs485_control { 6 7 unsigned short rts_on_send; 7 8 unsigned short rts_after_sent; 8 9 unsigned long delay_rts_before_send; 9 10 unsigned short enabled; 10 - #ifdef __KERNEL__ 11 - int disable_serial_loopback; 12 - #endif 13 11 }; 14 12 15 13 /* Used with ioctl() TIOCSERWRRS485 */
+1
arch/cris/include/asm/termios.h
··· 4 4 #include <asm/termbits.h> 5 5 #include <asm/ioctls.h> 6 6 #include <asm/rs485.h> 7 + #include <linux/serial.h> 7 8 8 9 struct winsize { 9 10 unsigned short ws_row;
+58 -21
drivers/serial/crisv10.c
··· 1391 1391 #if defined(CONFIG_ETRAX_RS485) 1392 1392 /* Enable RS-485 mode on selected port. This is UGLY. */ 1393 1393 static int 1394 - e100_enable_rs485(struct tty_struct *tty,struct rs485_control *r) 1394 + e100_enable_rs485(struct tty_struct *tty, struct serial_rs485 *r) 1395 1395 { 1396 1396 struct e100_serial * info = (struct e100_serial *)tty->driver_data; 1397 1397 ··· 1409 1409 CONFIG_ETRAX_RS485_LTC1387_RXEN_PORT_G_BIT, 1); 1410 1410 #endif 1411 1411 1412 - info->rs485.rts_on_send = 0x01 & r->rts_on_send; 1413 - info->rs485.rts_after_sent = 0x01 & r->rts_after_sent; 1412 + info->rs485.flags = r->flags; 1414 1413 if (r->delay_rts_before_send >= 1000) 1415 1414 info->rs485.delay_rts_before_send = 1000; 1416 1415 else 1417 1416 info->rs485.delay_rts_before_send = r->delay_rts_before_send; 1418 - info->rs485.enabled = r->enabled; 1419 1417 /* printk("rts: on send = %i, after = %i, enabled = %i", 1420 1418 info->rs485.rts_on_send, 1421 1419 info->rs485.rts_after_sent, ··· 1428 1430 const unsigned char *buf, int count) 1429 1431 { 1430 1432 struct e100_serial * info = (struct e100_serial *)tty->driver_data; 1431 - int old_enabled = info->rs485.enabled; 1433 + int old_value = (info->rs485.flags) & SER_RS485_ENABLED; 1432 1434 1433 1435 /* rs485 is always implicitly enabled if we're using the ioctl() 1434 - * but it doesn't have to be set in the rs485_control 1436 + * but it doesn't have to be set in the serial_rs485 1435 1437 * (to be backward compatible with old apps) 1436 1438 * So we store, set and restore it. 1437 1439 */ 1438 - info->rs485.enabled = 1; 1440 + info->rs485.flags |= SER_RS485_ENABLED; 1439 1441 /* rs_write now deals with RS485 if enabled */ 1440 1442 count = rs_write(tty, buf, count); 1441 - info->rs485.enabled = old_enabled; 1443 + if (!old_value) 1444 + info->rs485.flags &= ~(SER_RS485_ENABLED); 1442 1445 return count; 1443 1446 } 1444 1447 ··· 1450 1451 struct e100_serial *info = (struct e100_serial *)data; 1451 1452 1452 1453 fast_timers_rs485[info->line].function = NULL; 1453 - e100_rts(info, info->rs485.rts_after_sent); 1454 + e100_rts(info, (info->rs485.flags & SER_RS485_RTS_AFTER_SEND)); 1454 1455 #if defined(CONFIG_ETRAX_RS485_DISABLE_RECEIVER) 1455 1456 e100_enable_rx(info); 1456 1457 e100_enable_rx_irq(info); ··· 1646 1647 info->tr_running = 0; 1647 1648 1648 1649 #if defined(CONFIG_ETRAX_RS485) && defined(CONFIG_ETRAX_FAST_TIMER) 1649 - if (info->rs485.enabled) { 1650 + if (info->rs485.flags & SER_RS485_ENABLED) { 1650 1651 /* Set a short timer to toggle RTS */ 1651 1652 start_one_shot_timer(&fast_timers_rs485[info->line], 1652 1653 rs485_toggle_rts_timer_function, ··· 2576 2577 info->icount.tx++; 2577 2578 if (info->xmit.head == info->xmit.tail) { 2578 2579 #if defined(CONFIG_ETRAX_RS485) && defined(CONFIG_ETRAX_FAST_TIMER) 2579 - if (info->rs485.enabled) { 2580 + if (info->rs485.flags & SER_RS485_ENABLED) { 2580 2581 /* Set a short timer to toggle RTS */ 2581 2582 start_one_shot_timer(&fast_timers_rs485[info->line], 2582 2583 rs485_toggle_rts_timer_function, ··· 3217 3218 #if defined(CONFIG_ETRAX_RS485) 3218 3219 struct e100_serial *info = (struct e100_serial *)tty->driver_data; 3219 3220 3220 - if (info->rs485.enabled) 3221 + if (info->rs485.flags & SER_RS485_ENABLED) 3221 3222 { 3222 3223 /* If we are in RS-485 mode, we need to toggle RTS and disable 3223 3224 * the receiver before initiating a DMA transfer ··· 3227 3228 fast_timers_rs485[info->line].function = NULL; 3228 3229 del_fast_timer(&fast_timers_rs485[info->line]); 3229 3230 #endif 3230 - e100_rts(info, info->rs485.rts_on_send); 3231 + e100_rts(info, (info->rs485.flags & SER_RS485_RTS_ON_SEND)); 3231 3232 #if defined(CONFIG_ETRAX_RS485_DISABLE_RECEIVER) 3232 3233 e100_disable_rx(info); 3233 3234 e100_enable_rx_irq(info); ··· 3241 3242 count = rs_raw_write(tty, buf, count); 3242 3243 3243 3244 #if defined(CONFIG_ETRAX_RS485) 3244 - if (info->rs485.enabled) 3245 + if (info->rs485.flags & SER_RS485_ENABLED) 3245 3246 { 3246 3247 unsigned int val; 3247 3248 /* If we are in RS-485 mode the following has to be done: ··· 3262 3263 get_lsr_info(info, &val); 3263 3264 }while (!(val & TIOCSER_TEMT)); 3264 3265 3265 - e100_rts(info, info->rs485.rts_after_sent); 3266 + e100_rts(info, (info->rs485.flags & SER_RS485_RTS_AFTER_SEND)); 3266 3267 3267 3268 #if defined(CONFIG_ETRAX_RS485_DISABLE_RECEIVER) 3268 3269 e100_enable_rx(info); ··· 3677 3678 #if defined(CONFIG_ETRAX_RS485) 3678 3679 case TIOCSERSETRS485: 3679 3680 { 3681 + /* In this ioctl we still use the old structure 3682 + * rs485_control for backward compatibility 3683 + * (if we use serial_rs485, then old user-level code 3684 + * wouldn't work anymore...). 3685 + * The use of this ioctl is deprecated: use TIOCSRS485 3686 + * instead.*/ 3680 3687 struct rs485_control rs485ctrl; 3688 + struct serial_rs485 rs485data; 3689 + printk(KERN_DEBUG "The use of this ioctl is deprecated. Use TIOCSRS485 instead\n"); 3681 3690 if (copy_from_user(&rs485ctrl, (struct rs485_control *)arg, 3682 3691 sizeof(rs485ctrl))) 3683 3692 return -EFAULT; 3684 3693 3685 - return e100_enable_rs485(tty, &rs485ctrl); 3694 + rs485data.delay_rts_before_send = rs485ctrl.delay_rts_before_send; 3695 + rs485data.flags = 0; 3696 + if (rs485ctrl.enabled) 3697 + rs485data.flags |= SER_RS485_ENABLED; 3698 + else 3699 + rs485data.flags &= ~(SER_RS485_ENABLED); 3700 + 3701 + if (rs485ctrl.rts_on_send) 3702 + rs485data.flags |= SER_RS485_RTS_ON_SEND; 3703 + else 3704 + rs485data.flags &= ~(SER_RS485_RTS_ON_SEND); 3705 + 3706 + if (rs485ctrl.rts_after_sent) 3707 + rs485data.flags |= SER_RS485_RTS_AFTER_SEND; 3708 + else 3709 + rs485data.flags &= ~(SER_RS485_RTS_AFTER_SEND); 3710 + 3711 + return e100_enable_rs485(tty, &rs485data); 3686 3712 } 3713 + 3714 + case TIOCSRS485: 3715 + { 3716 + /* This is the new version of TIOCSRS485, with new 3717 + * data structure serial_rs485 */ 3718 + struct serial_rs485 rs485data; 3719 + if (copy_from_user(&rs485data, (struct rs485_control *)arg, 3720 + sizeof(rs485data))) 3721 + return -EFAULT; 3722 + 3723 + return e100_enable_rs485(tty, &rs485data); 3724 + } 3725 + 3687 3726 3688 3727 case TIOCSERWRRS485: 3689 3728 { ··· 3864 3827 /* port closed */ 3865 3828 3866 3829 #if defined(CONFIG_ETRAX_RS485) 3867 - if (info->rs485.enabled) { 3868 - info->rs485.enabled = 0; 3830 + if (info->rs485.flags & SER_RS485_ENABLED) { 3831 + info->rs485.flags &= ~(SER_RS485_ENABLED); 3869 3832 #if defined(CONFIG_ETRAX_RS485_ON_PA) 3870 3833 *R_PORT_PA_DATA = port_pa_data_shadow &= ~(1 << rs485_pa_bit); 3871 3834 #endif ··· 4530 4493 4531 4494 #if defined(CONFIG_ETRAX_RS485) 4532 4495 /* Set sane defaults */ 4533 - info->rs485.rts_on_send = 0; 4534 - info->rs485.rts_after_sent = 1; 4496 + info->rs485.flags &= ~(SER_RS485_RTS_ON_SEND); 4497 + info->rs485.flags |= SER_RS485_RTS_AFTER_SEND; 4535 4498 info->rs485.delay_rts_before_send = 0; 4536 - info->rs485.enabled = 0; 4499 + info->rs485.flags &= ~(SER_RS485_ENABLED); 4537 4500 #endif 4538 4501 INIT_WORK(&info->work, do_softint); 4539 4502
+1 -1
drivers/serial/crisv10.h
··· 125 125 int errorcode; 126 126 127 127 #ifdef CONFIG_ETRAX_RS485 128 - struct rs485_control rs485; /* RS-485 support */ 128 + struct serial_rs485 rs485; /* RS-485 support */ 129 129 #endif 130 130 }; 131 131