Skip to content

Commit

Permalink
tty: Pull the dtr raise into tty port
Browse files Browse the repository at this point in the history
This moves another per device special out of what should be shared open
wait paths into private methods

Signed-off-by: Alan Cox <alan@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Alan Cox authored and Linus Torvalds committed Jan 2, 2009
1 parent d0c9873 commit 5d951fb
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 25 deletions.
13 changes: 8 additions & 5 deletions drivers/char/isicom.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,19 +328,21 @@ static inline void drop_rts(struct isi_port *port)
}

/* card->lock MUST NOT be held */
static inline void raise_dtr_rts(struct isi_port *port)

static void isicom_raise_dtr_rts(struct tty_port *port)
{
struct isi_board *card = port->card;
struct isi_port *ip = container_of(port, struct isi_port, port);
struct isi_board *card = ip->card;
unsigned long base = card->base;
u16 channel = port->channel;
u16 channel = ip->channel;

if (!lock_card(card))
return;

outw(0x8000 | (channel << card->shift_count) | 0x02, base);
outw(0x0f04, base);
InterruptTheCard(base);
port->status |= (ISI_DTR | ISI_RTS);
ip->status |= (ISI_DTR | ISI_RTS);
unlock_card(card);
}

Expand Down Expand Up @@ -881,7 +883,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
spin_unlock_irqrestore(&card->card_lock, flags);

while (1) {
raise_dtr_rts(ip);
tty_port_raise_dtr_rts(port);

set_current_state(TASK_INTERRUPTIBLE);
if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)) {
Expand Down Expand Up @@ -1462,6 +1464,7 @@ static const struct tty_operations isicom_ops = {

static const struct tty_port_operations isicom_port_ops = {
.carrier_raised = isicom_carrier_raised,
.raise_dtr_rts = isicom_raise_dtr_rts,
};

static int __devinit reset_card(struct pci_dev *pdev,
Expand Down
17 changes: 13 additions & 4 deletions drivers/char/mxser.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,17 @@ static int mxser_carrier_raised(struct tty_port *port)
return (inb(mp->ioaddr + UART_MSR) & UART_MSR_DCD)?1:0;
}

static void mxser_raise_dtr_rts(struct tty_port *port)
{
struct mxser_port *mp = container_of(port, struct mxser_port, port);
unsigned long flags;

spin_lock_irqsave(&mp->slock, flags);
outb(inb(mp->ioaddr + UART_MCR) |
UART_MCR_DTR | UART_MCR_RTS, mp->ioaddr + UART_MCR);
spin_unlock_irqrestore(&mp->slock, flags);
}

static int mxser_block_til_ready(struct tty_struct *tty, struct file *filp,
struct mxser_port *mp)
{
Expand Down Expand Up @@ -586,10 +597,7 @@ static int mxser_block_til_ready(struct tty_struct *tty, struct file *filp,
spin_unlock_irqrestore(&mp->slock, flags);
port->blocked_open++;
while (1) {
spin_lock_irqsave(&mp->slock, flags);
outb(inb(mp->ioaddr + UART_MCR) |
UART_MCR_DTR | UART_MCR_RTS, mp->ioaddr + UART_MCR);
spin_unlock_irqrestore(&mp->slock, flags);
tty_port_raise_dtr_rts(port);
set_current_state(TASK_INTERRUPTIBLE);
if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)) {
if (port->flags & ASYNC_HUP_NOTIFY)
Expand Down Expand Up @@ -2458,6 +2466,7 @@ static const struct tty_operations mxser_ops = {

struct tty_port_operations mxser_port_ops = {
.carrier_raised = mxser_carrier_raised,
.raise_dtr_rts = mxser_raise_dtr_rts,
};

/*
Expand Down
14 changes: 10 additions & 4 deletions drivers/char/rocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,13 @@ static int carrier_raised(struct tty_port *port)
return (sGetChanStatusLo(&info->channel) & CD_ACT) ? 1 : 0;
}

static void raise_dtr_rts(struct tty_port *port)
{
struct r_port *info = container_of(port, struct r_port, port);
sSetDTR(&info->channel);
sSetRTS(&info->channel);
}

/* info->port.count is considered critical, protected by spinlocks. */
static int block_til_ready(struct tty_struct *tty, struct file *filp,
struct r_port *info)
Expand Down Expand Up @@ -928,10 +935,8 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
spin_unlock_irqrestore(&info->slock, flags);

while (1) {
if (tty->termios->c_cflag & CBAUD) {
sSetDTR(&info->channel);
sSetRTS(&info->channel);
}
if (tty->termios->c_cflag & CBAUD)
tty_port_raise_dtr_rts(port);
set_current_state(TASK_INTERRUPTIBLE);
if (tty_hung_up_p(filp) || !(info->flags & ROCKET_INITIALIZED)) {
if (info->flags & ROCKET_HUP_NOTIFY)
Expand Down Expand Up @@ -2381,6 +2386,7 @@ static const struct tty_operations rocket_ops = {

static const struct tty_port_operations rocket_port_ops = {
.carrier_raised = carrier_raised,
.raise_dtr_rts = raise_dtr_rts,
};

/*
Expand Down
21 changes: 15 additions & 6 deletions drivers/char/synclink.c
Original file line number Diff line number Diff line change
Expand Up @@ -3298,6 +3298,18 @@ static int carrier_raised(struct tty_port *port)
return (info->serial_signals & SerialSignal_DCD) ? 1 : 0;
}

static void raise_dtr_rts(struct tty_port *port)
{
struct mgsl_struct *info = container_of(port, struct mgsl_struct, port);
unsigned long flags;

spin_lock_irqsave(&info->irq_spinlock,flags);
info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR;
usc_set_serial_signals(info);
spin_unlock_irqrestore(&info->irq_spinlock,flags);
}


/* block_til_ready()
*
* Block the current process until the specified port
Expand Down Expand Up @@ -3358,12 +3370,8 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
port->blocked_open++;

while (1) {
if (tty->termios->c_cflag & CBAUD) {
spin_lock_irqsave(&info->irq_spinlock,flags);
info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR;
usc_set_serial_signals(info);
spin_unlock_irqrestore(&info->irq_spinlock,flags);
}
if (tty->termios->c_cflag & CBAUD)
tty_port_raise_dtr_rts(port);

set_current_state(TASK_INTERRUPTIBLE);

Expand Down Expand Up @@ -4321,6 +4329,7 @@ static void mgsl_add_device( struct mgsl_struct *info )

static const struct tty_port_operations mgsl_port_ops = {
.carrier_raised = carrier_raised,
.raise_dtr_rts = raise_dtr_rts,
};


Expand Down
21 changes: 15 additions & 6 deletions drivers/char/synclink_gt.c
Original file line number Diff line number Diff line change
Expand Up @@ -3143,6 +3143,18 @@ static int carrier_raised(struct tty_port *port)
return (info->signals & SerialSignal_DCD) ? 1 : 0;
}

static void raise_dtr_rts(struct tty_port *port)
{
unsigned long flags;
struct slgt_info *info = container_of(port, struct slgt_info, port);

spin_lock_irqsave(&info->lock,flags);
info->signals |= SerialSignal_RTS + SerialSignal_DTR;
set_signals(info);
spin_unlock_irqrestore(&info->lock,flags);
}


/*
* block current process until the device is ready to open
*/
Expand Down Expand Up @@ -3187,12 +3199,8 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
port->blocked_open++;

while (1) {
if ((tty->termios->c_cflag & CBAUD)) {
spin_lock_irqsave(&info->lock,flags);
info->signals |= SerialSignal_RTS + SerialSignal_DTR;
set_signals(info);
spin_unlock_irqrestore(&info->lock,flags);
}
if ((tty->termios->c_cflag & CBAUD))
tty_port_raise_dtr_rts(port);

set_current_state(TASK_INTERRUPTIBLE);

Expand Down Expand Up @@ -3455,6 +3463,7 @@ static void add_device(struct slgt_info *info)

static const struct tty_port_operations slgt_port_ops = {
.carrier_raised = carrier_raised,
.raise_dtr_rts = raise_dtr_rts,
};

/*
Expand Down
16 changes: 16 additions & 0 deletions drivers/char/tty_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,19 @@ int tty_port_carrier_raised(struct tty_port *port)
return port->ops->carrier_raised(port);
}
EXPORT_SYMBOL(tty_port_carrier_raised);

/**
* tty_port_raise_dtr_rts - Riase DTR/RTS
* @port: tty port
*
* Wrapper for the DTR/RTS raise logic. For the moment this is used
* to hide some internal details. This will eventually become entirely
* internal to the tty port.
*/

void tty_port_raise_dtr_rts(struct tty_port *port)
{
if (port->ops->raise_dtr_rts)
port->ops->raise_dtr_rts(port);
}
EXPORT_SYMBOL(tty_port_raise_dtr_rts);
2 changes: 2 additions & 0 deletions include/linux/tty.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ struct tty_port;
struct tty_port_operations {
/* Return 1 if the carrier is raised */
int (*carrier_raised)(struct tty_port *port);
void (*raise_dtr_rts)(struct tty_port *port);
};

struct tty_port {
Expand Down Expand Up @@ -436,6 +437,7 @@ extern void tty_port_free_xmit_buf(struct tty_port *port);
extern struct tty_struct *tty_port_tty_get(struct tty_port *port);
extern void tty_port_tty_set(struct tty_port *port, struct tty_struct *tty);
extern int tty_port_carrier_raised(struct tty_port *port);
extern void tty_port_raise_dtr_rts(struct tty_port *port);

extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
extern int tty_unregister_ldisc(int disc);
Expand Down

0 comments on commit 5d951fb

Please sign in to comment.