From: Jiri Slaby <jirislaby@gmail.com>
To: alan@lxorguk.ukuu.org.uk
Cc: Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org, Jiri Slaby <jirislaby@gmail.com>
Subject: [PATCH 11/13] Char: cyclades, tiocm cleanup
Date: Thu, 18 Jun 2009 09:41:46 +0200 [thread overview]
Message-ID: <1245310908-27691-11-git-send-email-jirislaby@gmail.com> (raw)
In-Reply-To: <1245310908-27691-1-git-send-email-jirislaby@gmail.com>
- save one indent level by inverting !fw_loaded condition
- read rs_status on Z and write it after we cahnge all the flags,
don't do that separately
- remove Y inverted rts/dtr branching, precompute registers and use
them
Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
---
drivers/char/cyclades.c | 153 ++++++++++++++++++++---------------------------
1 files changed, 66 insertions(+), 87 deletions(-)
diff --git a/drivers/char/cyclades.c b/drivers/char/cyclades.c
index 934eebe..ed9ec2c 100644
--- a/drivers/char/cyclades.c
+++ b/drivers/char/cyclades.c
@@ -830,6 +830,7 @@ static void cyy_change_rts_dtr(struct cyclades_port *info, unsigned int set,
struct cyclades_card *card = info->card;
void __iomem *base_addr;
int chip, channel, index;
+ u32 rts, dtr, msvrr, msvrd;
channel = info->line - card->first_line;
chip = channel >> 2;
@@ -837,29 +838,28 @@ static void cyy_change_rts_dtr(struct cyclades_port *info, unsigned int set,
index = card->bus_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) {
- cy_writeb(base_addr + (CyCAR << index), (u_char) channel);
- if (info->rtsdtr_inv) {
- cy_writeb(base_addr + (CyMSVR2 << index), CyDTR);
- } else {
- cy_writeb(base_addr + (CyMSVR1 << index), CyRTS);
- }
+ cy_writeb(base_addr + (CyCAR << index), (u8)channel);
+ cy_writeb(base_addr + (msvrr << index), rts);
}
if (clear & TIOCM_RTS) {
- cy_writeb(base_addr + (CyCAR << index), (u_char) channel);
- if (info->rtsdtr_inv) {
- cy_writeb(base_addr + (CyMSVR2 << index), ~CyDTR);
- } else {
- cy_writeb(base_addr + (CyMSVR1 << index), ~CyRTS);
- }
+ cy_writeb(base_addr + (CyCAR << index), (u8)channel);
+ cy_writeb(base_addr + (msvrr << index), ~rts);
}
if (set & TIOCM_DTR) {
- cy_writeb(base_addr + (CyCAR << index), (u_char) channel);
- if (info->rtsdtr_inv) {
- cy_writeb(base_addr + (CyMSVR1 << index), CyRTS);
- } else {
- cy_writeb(base_addr + (CyMSVR2 << index), CyDTR);
- }
+ cy_writeb(base_addr + (CyCAR << index), (u8)channel);
+ cy_writeb(base_addr + (msvrd << index), dtr);
#ifdef CY_DEBUG_DTR
printk(KERN_DEBUG "cyc:set_modem_info raising DTR\n");
printk(KERN_DEBUG " status: 0x%x, 0x%x\n",
@@ -868,13 +868,8 @@ static void cyy_change_rts_dtr(struct cyclades_port *info, unsigned int set,
#endif
}
if (clear & TIOCM_DTR) {
- cy_writeb(base_addr + (CyCAR << index), (u_char) channel);
- if (info->rtsdtr_inv) {
- cy_writeb(base_addr + (CyMSVR1 << index), ~CyRTS);
- } else {
- cy_writeb(base_addr + (CyMSVR2 << index), ~CyDTR);
- }
-
+ cy_writeb(base_addr + (CyCAR << index), (u8)channel);
+ cy_writeb(base_addr + (msvrd << index), ~dtr);
#ifdef CY_DEBUG_DTR
printk(KERN_DEBUG "cyc:set_modem_info dropping DTR\n");
printk(KERN_DEBUG " status: 0x%x, 0x%x\n",
@@ -2517,28 +2512,27 @@ static int cy_tiocmget(struct tty_struct *tty, struct file *file)
{
struct cyclades_port *info = tty->driver_data;
struct cyclades_card *card;
- int chip, channel, index;
void __iomem *base_addr;
- unsigned long flags;
- unsigned char status;
- unsigned long lstatus;
- unsigned int result;
+ int result, channel;
if (serial_paranoia_check(info, tty->name, __func__))
return -ENODEV;
- lock_kernel();
-
card = info->card;
channel = info->line - card->first_line;
+
+ lock_kernel();
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;
- index = card->bus_index;
base_addr = card->base_addr + (cy_chip_offset[chip] << index);
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 + (CyMSVR2 << index));
spin_unlock_irqrestore(&card->card_lock, flags);
@@ -2555,21 +2549,22 @@ static int cy_tiocmget(struct tty_struct *tty, struct file *file)
((status & CyDSR) ? TIOCM_DSR : 0) |
((status & CyCTS) ? TIOCM_CTS : 0);
} else {
- if (cyz_is_loaded(card)) {
- 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);
- } else {
- result = 0;
- unlock_kernel();
- return -ENODEV;
+ u32 lstatus;
+
+ if (!cyz_is_loaded(card)) {
+ result = -ENODEV;
+ goto end;
}
+ 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();
return result;
} /* cy_tiomget */
@@ -2581,68 +2576,52 @@ cy_tiocmset(struct tty_struct *tty, struct file *file,
struct cyclades_port *info = tty->driver_data;
struct cyclades_card *card;
unsigned long flags;
- int channel, retval;
if (serial_paranoia_check(info, tty->name, __func__))
return -ENODEV;
card = info->card;
- channel = (info->line) - (card->first_line);
if (!cy_is_Z(card)) {
spin_lock_irqsave(&card->card_lock, flags);
cyy_change_rts_dtr(info, set, clear);
spin_unlock_irqrestore(&card->card_lock, flags);
} else {
- if (cyz_is_loaded(card)) {
- struct CH_CTRL __iomem *ch_ctrl = info->u.cyz.ch_ctrl;
-
- if (set & TIOCM_RTS) {
- spin_lock_irqsave(&card->card_lock, flags);
- cy_writel(&ch_ctrl->rs_control,
- readl(&ch_ctrl->rs_control) | C_RS_RTS);
- spin_unlock_irqrestore(&card->card_lock, flags);
- }
- if (clear & TIOCM_RTS) {
- spin_lock_irqsave(&card->card_lock, flags);
- cy_writel(&ch_ctrl->rs_control,
- readl(&ch_ctrl->rs_control) &
- ~C_RS_RTS);
- spin_unlock_irqrestore(&card->card_lock, flags);
- }
- 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);
+ struct CH_CTRL __iomem *ch_ctrl = info->u.cyz.ch_ctrl;
+ int retval, channel = info->line - card->first_line;
+ u32 rs;
+
+ if (!cyz_is_loaded(card))
+ return -ENODEV;
+
+ spin_lock_irqsave(&card->card_lock, flags);
+ rs = readl(&ch_ctrl->rs_control);
+ if (set & TIOCM_RTS)
+ rs |= C_RS_RTS;
+ if (clear & TIOCM_RTS)
+ rs &= ~C_RS_RTS;
+ if (set & TIOCM_DTR) {
+ rs |= C_RS_DTR;
#ifdef CY_DEBUG_DTR
- printk(KERN_DEBUG "cyc:set_modem_info raising "
- "Z DTR\n");
+ printk(KERN_DEBUG "cyc:set_modem_info raising Z DTR\n");
#endif
- spin_unlock_irqrestore(&card->card_lock, flags);
- }
- if (clear & TIOCM_DTR) {
- spin_lock_irqsave(&card->card_lock, flags);
- cy_writel(&ch_ctrl->rs_control,
- readl(&ch_ctrl->rs_control) &
- ~C_RS_DTR);
+ }
+ if (clear & TIOCM_DTR) {
+ rs &= ~C_RS_DTR;
#ifdef CY_DEBUG_DTR
- printk(KERN_DEBUG "cyc:set_modem_info clearing "
- "Z DTR\n");
+ printk(KERN_DEBUG "cyc:set_modem_info clearing "
+ "Z DTR\n");
#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);
+ spin_unlock_irqrestore(&card->card_lock, flags);
if (retval != 0) {
printk(KERN_ERR "cyc:set_modem_info retval on ttyC%d "
"was %x\n", info->line, retval);
}
- spin_unlock_irqrestore(&card->card_lock, flags);
}
return 0;
-} /* cy_tiocmset */
+}
/*
* cy_break() --- routine which turns the break handling on or off
--
1.6.3.2
next prev parent reply other threads:[~2009-06-18 7:44 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-18 7:41 [PATCH 01/13] Char: cyclades, add tty refcounting Jiri Slaby
2009-06-18 7:41 ` [PATCH 02/13] Char: cyclades, remove block_til_ready Jiri Slaby
2009-06-18 7:41 ` [PATCH 03/13] Char: cyclades, avoid addresses recomputation Jiri Slaby
2009-06-18 7:41 ` [PATCH 04/13] Char: cyclades, switch to tty_port_hangup Jiri Slaby
2009-06-18 7:41 ` [PATCH 05/13] Char: cyclades, close cleanup Jiri Slaby
2009-06-18 7:41 ` [PATCH 06/13] Char: cyclades, overall cleanup Jiri Slaby
2009-06-18 7:41 ` [PATCH 07/13] Char: cyclades, sleep instead busy-wait Jiri Slaby
2009-06-18 7:41 ` [PATCH 08/13] Char: cyclades, use dtr_rts helpers Jiri Slaby
2009-06-18 7:41 ` [PATCH 09/13] Char: cyclades, merge cy_startup tails Jiri Slaby
2009-06-18 7:41 ` [PATCH 10/13] Char: cyclades, ioctls cleanup Jiri Slaby
2009-06-18 7:41 ` Jiri Slaby [this message]
2009-06-18 7:41 ` [PATCH 12/13] Char: cyclades, introduce cyy_readb/writeb Jiri Slaby
2009-06-18 7:41 ` [PATCH 13/13] Char: cyclades, remove more duplicated code Jiri Slaby
2009-06-18 13:17 ` [PATCH 01/13] Char: cyclades, add tty refcounting Alan Cox
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1245310908-27691-11-git-send-email-jirislaby@gmail.com \
--to=jirislaby@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®