Commit 0d348729 authored by Jiri Slaby's avatar Jiri Slaby Committed by Live-CD User

cyclades: tiocm cleanup

- save one indent level by inverting !fw_loaded condition
- read rs_status on Z and write it after we change all the flags,
  don't do that separately
- remove Y inverted rts/dtr branching, precompute registers and use
  them
Signed-off-by: default avatarJiri Slaby <jirislaby@gmail.com>
Signed-off-by: default avatarAlan Cox <alan@linux.intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 6c28181c
No related merge requests found
...@@ -831,6 +831,7 @@ static void cyy_change_rts_dtr(struct cyclades_port *info, unsigned int set, ...@@ -831,6 +831,7 @@ static void cyy_change_rts_dtr(struct cyclades_port *info, unsigned int set,
struct cyclades_card *card = info->card; struct cyclades_card *card = info->card;
void __iomem *base_addr; void __iomem *base_addr;
int chip, channel, index; int chip, channel, index;
u32 rts, dtr, msvrr, msvrd;
channel = info->line - card->first_line; channel = info->line - card->first_line;
chip = channel >> 2; chip = channel >> 2;
...@@ -838,29 +839,28 @@ static void cyy_change_rts_dtr(struct cyclades_port *info, unsigned int set, ...@@ -838,29 +839,28 @@ static void cyy_change_rts_dtr(struct cyclades_port *info, unsigned int set,
index = card->bus_index; index = card->bus_index;
base_addr = card->base_addr + (cy_chip_offset[chip] << index); base_addr = card->base_addr + (cy_chip_offset[chip] << index);
if (info->rtsdtr_inv) {
msvrr = CyMSVR2;
msvrd = CyMSVR1;
rts = CyDTR;
dtr = CyRTS;
} else {
msvrr = CyMSVR1;
msvrd = CyMSVR2;
rts = CyRTS;
dtr = CyDTR;
}
if (set & TIOCM_RTS) { if (set & TIOCM_RTS) {
cy_writeb(base_addr + (CyCAR << index), (u_char) channel); cy_writeb(base_addr + (CyCAR << index), (u8)channel);
if (info->rtsdtr_inv) { cy_writeb(base_addr + (msvrr << index), rts);
cy_writeb(base_addr + (CyMSVR2 << index), CyDTR);
} else {
cy_writeb(base_addr + (CyMSVR1 << index), CyRTS);
}
} }
if (clear & TIOCM_RTS) { if (clear & TIOCM_RTS) {
cy_writeb(base_addr + (CyCAR << index), (u_char) channel); cy_writeb(base_addr + (CyCAR << index), (u8)channel);
if (info->rtsdtr_inv) { cy_writeb(base_addr + (msvrr << index), ~rts);
cy_writeb(base_addr + (CyMSVR2 << index), ~CyDTR);
} else {
cy_writeb(base_addr + (CyMSVR1 << index), ~CyRTS);
}
} }
if (set & TIOCM_DTR) { if (set & TIOCM_DTR) {
cy_writeb(base_addr + (CyCAR << index), (u_char) channel); cy_writeb(base_addr + (CyCAR << index), (u8)channel);
if (info->rtsdtr_inv) { cy_writeb(base_addr + (msvrd << index), dtr);
cy_writeb(base_addr + (CyMSVR1 << index), CyRTS);
} else {
cy_writeb(base_addr + (CyMSVR2 << index), CyDTR);
}
#ifdef CY_DEBUG_DTR #ifdef CY_DEBUG_DTR
printk(KERN_DEBUG "cyc:set_modem_info raising DTR\n"); printk(KERN_DEBUG "cyc:set_modem_info raising DTR\n");
printk(KERN_DEBUG " status: 0x%x, 0x%x\n", printk(KERN_DEBUG " status: 0x%x, 0x%x\n",
...@@ -869,13 +869,8 @@ static void cyy_change_rts_dtr(struct cyclades_port *info, unsigned int set, ...@@ -869,13 +869,8 @@ static void cyy_change_rts_dtr(struct cyclades_port *info, unsigned int set,
#endif #endif
} }
if (clear & TIOCM_DTR) { if (clear & TIOCM_DTR) {
cy_writeb(base_addr + (CyCAR << index), (u_char) channel); cy_writeb(base_addr + (CyCAR << index), (u8)channel);
if (info->rtsdtr_inv) { cy_writeb(base_addr + (msvrd << index), ~dtr);
cy_writeb(base_addr + (CyMSVR1 << index), ~CyRTS);
} else {
cy_writeb(base_addr + (CyMSVR2 << index), ~CyDTR);
}
#ifdef CY_DEBUG_DTR #ifdef CY_DEBUG_DTR
printk(KERN_DEBUG "cyc:set_modem_info dropping DTR\n"); printk(KERN_DEBUG "cyc:set_modem_info dropping DTR\n");
printk(KERN_DEBUG " status: 0x%x, 0x%x\n", printk(KERN_DEBUG " status: 0x%x, 0x%x\n",
...@@ -2518,28 +2513,27 @@ static int cy_tiocmget(struct tty_struct *tty, struct file *file) ...@@ -2518,28 +2513,27 @@ static int cy_tiocmget(struct tty_struct *tty, struct file *file)
{ {
struct cyclades_port *info = tty->driver_data; struct cyclades_port *info = tty->driver_data;
struct cyclades_card *card; struct cyclades_card *card;
int chip, channel, index;
void __iomem *base_addr; void __iomem *base_addr;
unsigned long flags; int result, channel;
unsigned char status;
unsigned long lstatus;
unsigned int result;
if (serial_paranoia_check(info, tty->name, __func__)) if (serial_paranoia_check(info, tty->name, __func__))
return -ENODEV; return -ENODEV;
lock_kernel();
card = info->card; card = info->card;
channel = info->line - card->first_line; channel = info->line - card->first_line;
lock_kernel();
if (!cy_is_Z(card)) { if (!cy_is_Z(card)) {
chip = channel >> 2; unsigned long flags;
unsigned char status;
int chip = channel >> 2;
int index = card->bus_index;
channel &= 0x03; channel &= 0x03;
index = card->bus_index;
base_addr = card->base_addr + (cy_chip_offset[chip] << index); base_addr = card->base_addr + (cy_chip_offset[chip] << index);
spin_lock_irqsave(&card->card_lock, flags); spin_lock_irqsave(&card->card_lock, flags);
cy_writeb(base_addr + (CyCAR << index), (u_char) channel); cy_writeb(base_addr + (CyCAR << index), (u8)channel);
status = readb(base_addr + (CyMSVR1 << index)); status = readb(base_addr + (CyMSVR1 << index));
status |= readb(base_addr + (CyMSVR2 << index)); status |= readb(base_addr + (CyMSVR2 << index));
spin_unlock_irqrestore(&card->card_lock, flags); spin_unlock_irqrestore(&card->card_lock, flags);
...@@ -2556,21 +2550,22 @@ static int cy_tiocmget(struct tty_struct *tty, struct file *file) ...@@ -2556,21 +2550,22 @@ static int cy_tiocmget(struct tty_struct *tty, struct file *file)
((status & CyDSR) ? TIOCM_DSR : 0) | ((status & CyDSR) ? TIOCM_DSR : 0) |
((status & CyCTS) ? TIOCM_CTS : 0); ((status & CyCTS) ? TIOCM_CTS : 0);
} else { } else {
if (cyz_is_loaded(card)) { u32 lstatus;
lstatus = readl(&info->u.cyz.ch_ctrl->rs_status);
result = ((lstatus & C_RS_RTS) ? TIOCM_RTS : 0) | if (!cyz_is_loaded(card)) {
((lstatus & C_RS_DTR) ? TIOCM_DTR : 0) | result = -ENODEV;
((lstatus & C_RS_DCD) ? TIOCM_CAR : 0) | goto end;
((lstatus & C_RS_RI) ? TIOCM_RNG : 0) |
((lstatus & C_RS_DSR) ? TIOCM_DSR : 0) |
((lstatus & C_RS_CTS) ? TIOCM_CTS : 0);
} else {
result = 0;
unlock_kernel();
return -ENODEV;
} }
lstatus = readl(&info->u.cyz.ch_ctrl->rs_status);
result = ((lstatus & C_RS_RTS) ? TIOCM_RTS : 0) |
((lstatus & C_RS_DTR) ? TIOCM_DTR : 0) |
((lstatus & C_RS_DCD) ? TIOCM_CAR : 0) |
((lstatus & C_RS_RI) ? TIOCM_RNG : 0) |
((lstatus & C_RS_DSR) ? TIOCM_DSR : 0) |
((lstatus & C_RS_CTS) ? TIOCM_CTS : 0);
} }
end:
unlock_kernel(); unlock_kernel();
return result; return result;
} /* cy_tiomget */ } /* cy_tiomget */
...@@ -2582,68 +2577,52 @@ cy_tiocmset(struct tty_struct *tty, struct file *file, ...@@ -2582,68 +2577,52 @@ cy_tiocmset(struct tty_struct *tty, struct file *file,
struct cyclades_port *info = tty->driver_data; struct cyclades_port *info = tty->driver_data;
struct cyclades_card *card; struct cyclades_card *card;
unsigned long flags; unsigned long flags;
int channel, retval;
if (serial_paranoia_check(info, tty->name, __func__)) if (serial_paranoia_check(info, tty->name, __func__))
return -ENODEV; return -ENODEV;
card = info->card; card = info->card;
channel = (info->line) - (card->first_line);
if (!cy_is_Z(card)) { if (!cy_is_Z(card)) {
spin_lock_irqsave(&card->card_lock, flags); spin_lock_irqsave(&card->card_lock, flags);
cyy_change_rts_dtr(info, set, clear); cyy_change_rts_dtr(info, set, clear);
spin_unlock_irqrestore(&card->card_lock, flags); spin_unlock_irqrestore(&card->card_lock, flags);
} else { } else {
if (cyz_is_loaded(card)) { struct CH_CTRL __iomem *ch_ctrl = info->u.cyz.ch_ctrl;
struct CH_CTRL __iomem *ch_ctrl = info->u.cyz.ch_ctrl; int retval, channel = info->line - card->first_line;
u32 rs;
if (set & TIOCM_RTS) {
spin_lock_irqsave(&card->card_lock, flags); if (!cyz_is_loaded(card))
cy_writel(&ch_ctrl->rs_control, return -ENODEV;
readl(&ch_ctrl->rs_control) | C_RS_RTS);
spin_unlock_irqrestore(&card->card_lock, flags); spin_lock_irqsave(&card->card_lock, flags);
} rs = readl(&ch_ctrl->rs_control);
if (clear & TIOCM_RTS) { if (set & TIOCM_RTS)
spin_lock_irqsave(&card->card_lock, flags); rs |= C_RS_RTS;
cy_writel(&ch_ctrl->rs_control, if (clear & TIOCM_RTS)
readl(&ch_ctrl->rs_control) & rs &= ~C_RS_RTS;
~C_RS_RTS); if (set & TIOCM_DTR) {
spin_unlock_irqrestore(&card->card_lock, flags); rs |= C_RS_DTR;
}
if (set & TIOCM_DTR) {
spin_lock_irqsave(&card->card_lock, flags);
cy_writel(&ch_ctrl->rs_control,
readl(&ch_ctrl->rs_control) | C_RS_DTR);
#ifdef CY_DEBUG_DTR #ifdef CY_DEBUG_DTR
printk(KERN_DEBUG "cyc:set_modem_info raising " printk(KERN_DEBUG "cyc:set_modem_info raising Z DTR\n");
"Z DTR\n");
#endif #endif
spin_unlock_irqrestore(&card->card_lock, flags); }
} if (clear & TIOCM_DTR) {
if (clear & TIOCM_DTR) { rs &= ~C_RS_DTR;
spin_lock_irqsave(&card->card_lock, flags);
cy_writel(&ch_ctrl->rs_control,
readl(&ch_ctrl->rs_control) &
~C_RS_DTR);
#ifdef CY_DEBUG_DTR #ifdef CY_DEBUG_DTR
printk(KERN_DEBUG "cyc:set_modem_info clearing " printk(KERN_DEBUG "cyc:set_modem_info clearing "
"Z DTR\n"); "Z DTR\n");
#endif #endif
spin_unlock_irqrestore(&card->card_lock, flags);
}
} else {
return -ENODEV;
} }
spin_lock_irqsave(&card->card_lock, flags); cy_writel(&ch_ctrl->rs_control, rs);
retval = cyz_issue_cmd(card, channel, C_CM_IOCTLM, 0L); retval = cyz_issue_cmd(card, channel, C_CM_IOCTLM, 0L);
spin_unlock_irqrestore(&card->card_lock, flags);
if (retval != 0) { if (retval != 0) {
printk(KERN_ERR "cyc:set_modem_info retval on ttyC%d " printk(KERN_ERR "cyc:set_modem_info retval on ttyC%d "
"was %x\n", info->line, retval); "was %x\n", info->line, retval);
} }
spin_unlock_irqrestore(&card->card_lock, flags);
} }
return 0; return 0;
} /* cy_tiocmset */ }
/* /*
* cy_break() --- routine which turns the break handling on or off * cy_break() --- routine which turns the break handling on or off
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment