aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/moxa.c
diff options
context:
space:
mode:
authorJiri Slaby <jirislaby@gmail.com>2008-04-30 03:53:44 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-04-30 11:29:43 -0400
commit2108eba5c531c12f5ae2ed2ef4cee7bf4246897b (patch)
tree2dc0507b8d9a88945c0737acf7b9a794186ee62b /drivers/char/moxa.c
parent7bcf97d1dd88135b58c7adb7c3bfebab55b21a20 (diff)
Char: moxa, cleanup rx/tx
- cleanup types - use tty_prepare_flip_string and io memcpys Signed-off-by: Jiri Slaby <jirislaby@gmail.com> Tested-by: Oyvind Aabling <Oyvind.Aabling@uni-c.dk> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/char/moxa.c')
-rw-r--r--drivers/char/moxa.c124
1 files changed, 50 insertions, 74 deletions
diff --git a/drivers/char/moxa.c b/drivers/char/moxa.c
index a64707623e47..797284fe5fce 100644
--- a/drivers/char/moxa.c
+++ b/drivers/char/moxa.c
@@ -224,7 +224,7 @@ static void MoxaPortLineCtrl(struct moxa_port *, int, int);
224static void MoxaPortFlowCtrl(struct moxa_port *, int, int, int, int, int); 224static void MoxaPortFlowCtrl(struct moxa_port *, int, int, int, int, int);
225static int MoxaPortLineStatus(struct moxa_port *); 225static int MoxaPortLineStatus(struct moxa_port *);
226static void MoxaPortFlushData(struct moxa_port *, int); 226static void MoxaPortFlushData(struct moxa_port *, int);
227static int MoxaPortWriteData(struct moxa_port *, unsigned char *, int); 227static int MoxaPortWriteData(struct moxa_port *, const unsigned char *, int);
228static int MoxaPortReadData(struct moxa_port *); 228static int MoxaPortReadData(struct moxa_port *);
229static int MoxaPortTxQueue(struct moxa_port *); 229static int MoxaPortTxQueue(struct moxa_port *);
230static int MoxaPortRxQueue(struct moxa_port *); 230static int MoxaPortRxQueue(struct moxa_port *);
@@ -1165,7 +1165,7 @@ static int moxa_write(struct tty_struct *tty,
1165 return 0; 1165 return 0;
1166 1166
1167 spin_lock_bh(&moxa_lock); 1167 spin_lock_bh(&moxa_lock);
1168 len = MoxaPortWriteData(ch, (unsigned char *) buf, count); 1168 len = MoxaPortWriteData(ch, buf, count);
1169 spin_unlock_bh(&moxa_lock); 1169 spin_unlock_bh(&moxa_lock);
1170 1170
1171 /********************************************* 1171 /*********************************************
@@ -2030,15 +2030,13 @@ static int MoxaPortLineStatus(struct moxa_port *port)
2030 return val; 2030 return val;
2031} 2031}
2032 2032
2033static int MoxaPortWriteData(struct moxa_port *port, unsigned char *buffer, 2033static int MoxaPortWriteData(struct moxa_port *port,
2034 int len) 2034 const unsigned char *buffer, int len)
2035{ 2035{
2036 int c, total, i;
2037 ushort tail;
2038 int cnt;
2039 ushort head, tx_mask, spage, epage;
2040 ushort pageno, pageofs, bufhead;
2041 void __iomem *baseAddr, *ofsAddr, *ofs; 2036 void __iomem *baseAddr, *ofsAddr, *ofs;
2037 unsigned int c, total;
2038 u16 head, tail, tx_mask, spage, epage;
2039 u16 pageno, pageofs, bufhead;
2042 2040
2043 ofsAddr = port->tableAddr; 2041 ofsAddr = port->tableAddr;
2044 baseAddr = port->board->basemem; 2042 baseAddr = port->board->basemem;
@@ -2047,8 +2045,7 @@ static int MoxaPortWriteData(struct moxa_port *port, unsigned char *buffer,
2047 epage = readw(ofsAddr + EndPage_txb); 2045 epage = readw(ofsAddr + EndPage_txb);
2048 tail = readw(ofsAddr + TXwptr); 2046 tail = readw(ofsAddr + TXwptr);
2049 head = readw(ofsAddr + TXrptr); 2047 head = readw(ofsAddr + TXrptr);
2050 c = (head > tail) ? (head - tail - 1) 2048 c = (head > tail) ? (head - tail - 1) : (head - tail + tx_mask);
2051 : (head - tail + tx_mask);
2052 if (c > len) 2049 if (c > len)
2053 c = len; 2050 c = len;
2054 moxaLog.txcnt[port->tty->index] += c; 2051 moxaLog.txcnt[port->tty->index] += c;
@@ -2063,46 +2060,42 @@ static int MoxaPortWriteData(struct moxa_port *port, unsigned char *buffer,
2063 len = tx_mask + 1 - tail; 2060 len = tx_mask + 1 - tail;
2064 len = (c > len) ? len : c; 2061 len = (c > len) ? len : c;
2065 ofs = baseAddr + DynPage_addr + bufhead + tail; 2062 ofs = baseAddr + DynPage_addr + bufhead + tail;
2066 for (i = 0; i < len; i++) 2063 memcpy_toio(ofs, buffer, len);
2067 writeb(*buffer++, ofs + i); 2064 buffer += len;
2068 tail = (tail + len) & tx_mask; 2065 tail = (tail + len) & tx_mask;
2069 c -= len; 2066 c -= len;
2070 } 2067 }
2071 writew(tail, ofsAddr + TXwptr);
2072 } else { 2068 } else {
2073 len = c;
2074 pageno = spage + (tail >> 13); 2069 pageno = spage + (tail >> 13);
2075 pageofs = tail & Page_mask; 2070 pageofs = tail & Page_mask;
2076 do { 2071 while (c > 0) {
2077 cnt = Page_size - pageofs; 2072 len = Page_size - pageofs;
2078 if (cnt > c) 2073 if (len > c)
2079 cnt = c; 2074 len = c;
2080 c -= cnt;
2081 writeb(pageno, baseAddr + Control_reg); 2075 writeb(pageno, baseAddr + Control_reg);
2082 ofs = baseAddr + DynPage_addr + pageofs; 2076 ofs = baseAddr + DynPage_addr + pageofs;
2083 for (i = 0; i < cnt; i++) 2077 memcpy_toio(ofs, buffer, len);
2084 writeb(*buffer++, ofs + i); 2078 buffer += len;
2085 if (c == 0) {
2086 writew((tail + len) & tx_mask, ofsAddr + TXwptr);
2087 break;
2088 }
2089 if (++pageno == epage) 2079 if (++pageno == epage)
2090 pageno = spage; 2080 pageno = spage;
2091 pageofs = 0; 2081 pageofs = 0;
2092 } while (1); 2082 c -= len;
2083 }
2084 tail = (tail + total) & tx_mask;
2093 } 2085 }
2086 writew(tail, ofsAddr + TXwptr);
2094 writeb(1, ofsAddr + CD180TXirq); /* start to send */ 2087 writeb(1, ofsAddr + CD180TXirq); /* start to send */
2095 return (total); 2088 return total;
2096} 2089}
2097 2090
2098static int MoxaPortReadData(struct moxa_port *port) 2091static int MoxaPortReadData(struct moxa_port *port)
2099{ 2092{
2100 struct tty_struct *tty = port->tty; 2093 struct tty_struct *tty = port->tty;
2101 register ushort head, pageofs; 2094 unsigned char *dst;
2102 int i, count, cnt, len, total, remain;
2103 ushort tail, rx_mask, spage, epage;
2104 ushort pageno, bufhead;
2105 void __iomem *baseAddr, *ofsAddr, *ofs; 2095 void __iomem *baseAddr, *ofsAddr, *ofs;
2096 unsigned int count, len, total;
2097 u16 tail, rx_mask, spage, epage;
2098 u16 pageno, pageofs, bufhead, head;
2106 2099
2107 ofsAddr = port->tableAddr; 2100 ofsAddr = port->tableAddr;
2108 baseAddr = port->board->basemem; 2101 baseAddr = port->board->basemem;
@@ -2111,101 +2104,84 @@ static int MoxaPortReadData(struct moxa_port *port)
2111 rx_mask = readw(ofsAddr + RX_mask); 2104 rx_mask = readw(ofsAddr + RX_mask);
2112 spage = readw(ofsAddr + Page_rxb); 2105 spage = readw(ofsAddr + Page_rxb);
2113 epage = readw(ofsAddr + EndPage_rxb); 2106 epage = readw(ofsAddr + EndPage_rxb);
2114 count = (tail >= head) ? (tail - head) 2107 count = (tail >= head) ? (tail - head) : (tail - head + rx_mask + 1);
2115 : (tail - head + rx_mask + 1);
2116 if (count == 0) 2108 if (count == 0)
2117 return 0; 2109 return 0;
2118 2110
2119 total = count; 2111 total = count;
2120 remain = count - total;
2121 moxaLog.rxcnt[tty->index] += total; 2112 moxaLog.rxcnt[tty->index] += total;
2122 count = total;
2123 if (spage == epage) { 2113 if (spage == epage) {
2124 bufhead = readw(ofsAddr + Ofs_rxb); 2114 bufhead = readw(ofsAddr + Ofs_rxb);
2125 writew(spage, baseAddr + Control_reg); 2115 writew(spage, baseAddr + Control_reg);
2126 while (count > 0) { 2116 while (count > 0) {
2127 if (tail >= head)
2128 len = tail - head;
2129 else
2130 len = rx_mask + 1 - head;
2131 len = (count > len) ? len : count;
2132 ofs = baseAddr + DynPage_addr + bufhead + head; 2117 ofs = baseAddr + DynPage_addr + bufhead + head;
2133 for (i = 0; i < len; i++) 2118 len = (tail >= head) ? (tail - head) :
2134 tty_insert_flip_char(tty, readb(ofs + i), TTY_NORMAL); 2119 (rx_mask + 1 - head);
2120 len = tty_prepare_flip_string(tty, &dst,
2121 min(len, count));
2122 memcpy_fromio(dst, ofs, len);
2135 head = (head + len) & rx_mask; 2123 head = (head + len) & rx_mask;
2136 count -= len; 2124 count -= len;
2137 } 2125 }
2138 writew(head, ofsAddr + RXrptr);
2139 } else { 2126 } else {
2140 len = count;
2141 pageno = spage + (head >> 13); 2127 pageno = spage + (head >> 13);
2142 pageofs = head & Page_mask; 2128 pageofs = head & Page_mask;
2143 do { 2129 while (count > 0) {
2144 cnt = Page_size - pageofs;
2145 if (cnt > count)
2146 cnt = count;
2147 count -= cnt;
2148 writew(pageno, baseAddr + Control_reg); 2130 writew(pageno, baseAddr + Control_reg);
2149 ofs = baseAddr + DynPage_addr + pageofs; 2131 ofs = baseAddr + DynPage_addr + pageofs;
2150 for (i = 0; i < cnt; i++) 2132 len = tty_prepare_flip_string(tty, &dst,
2151 tty_insert_flip_char(tty, readb(ofs + i), TTY_NORMAL); 2133 min(Page_size - pageofs, count));
2152 if (count == 0) { 2134 memcpy_fromio(dst, ofs, len);
2153 writew((head + len) & rx_mask, ofsAddr + RXrptr); 2135
2154 break; 2136 count -= len;
2155 } 2137 pageofs = (pageofs + len) & Page_mask;
2156 if (++pageno == epage) 2138 if (pageofs == 0 && ++pageno == epage)
2157 pageno = spage; 2139 pageno = spage;
2158 pageofs = 0; 2140 }
2159 } while (1); 2141 head = (head + total) & rx_mask;
2160 } 2142 }
2161 if ((readb(ofsAddr + FlagStat) & Xoff_state) && (remain < LowWater)) { 2143 writew(head, ofsAddr + RXrptr);
2144 if (readb(ofsAddr + FlagStat) & Xoff_state) {
2162 moxaLowWaterChk = 1; 2145 moxaLowWaterChk = 1;
2163 port->lowChkFlag = 1; 2146 port->lowChkFlag = 1;
2164 } 2147 }
2165 return (total); 2148 return total;
2166} 2149}
2167 2150
2168 2151
2169static int MoxaPortTxQueue(struct moxa_port *port) 2152static int MoxaPortTxQueue(struct moxa_port *port)
2170{ 2153{
2171 void __iomem *ofsAddr = port->tableAddr; 2154 void __iomem *ofsAddr = port->tableAddr;
2172 ushort rptr, wptr, mask; 2155 u16 rptr, wptr, mask;
2173 int len;
2174 2156
2175 rptr = readw(ofsAddr + TXrptr); 2157 rptr = readw(ofsAddr + TXrptr);
2176 wptr = readw(ofsAddr + TXwptr); 2158 wptr = readw(ofsAddr + TXwptr);
2177 mask = readw(ofsAddr + TX_mask); 2159 mask = readw(ofsAddr + TX_mask);
2178 len = (wptr - rptr) & mask; 2160 return (wptr - rptr) & mask;
2179 return (len);
2180} 2161}
2181 2162
2182static int MoxaPortTxFree(struct moxa_port *port) 2163static int MoxaPortTxFree(struct moxa_port *port)
2183{ 2164{
2184 void __iomem *ofsAddr = port->tableAddr; 2165 void __iomem *ofsAddr = port->tableAddr;
2185 ushort rptr, wptr, mask; 2166 u16 rptr, wptr, mask;
2186 int len;
2187 2167
2188 rptr = readw(ofsAddr + TXrptr); 2168 rptr = readw(ofsAddr + TXrptr);
2189 wptr = readw(ofsAddr + TXwptr); 2169 wptr = readw(ofsAddr + TXwptr);
2190 mask = readw(ofsAddr + TX_mask); 2170 mask = readw(ofsAddr + TX_mask);
2191 len = mask - ((wptr - rptr) & mask); 2171 return mask - ((wptr - rptr) & mask);
2192 return (len);
2193} 2172}
2194 2173
2195static int MoxaPortRxQueue(struct moxa_port *port) 2174static int MoxaPortRxQueue(struct moxa_port *port)
2196{ 2175{
2197 void __iomem *ofsAddr = port->tableAddr; 2176 void __iomem *ofsAddr = port->tableAddr;
2198 ushort rptr, wptr, mask; 2177 u16 rptr, wptr, mask;
2199 int len;
2200 2178
2201 rptr = readw(ofsAddr + RXrptr); 2179 rptr = readw(ofsAddr + RXrptr);
2202 wptr = readw(ofsAddr + RXwptr); 2180 wptr = readw(ofsAddr + RXwptr);
2203 mask = readw(ofsAddr + RX_mask); 2181 mask = readw(ofsAddr + RX_mask);
2204 len = (wptr - rptr) & mask; 2182 return (wptr - rptr) & mask;
2205 return (len);
2206} 2183}
2207 2184
2208
2209static void MoxaPortTxDisable(struct moxa_port *port) 2185static void MoxaPortTxDisable(struct moxa_port *port)
2210{ 2186{
2211 moxafunc(port->tableAddr, FC_SetXoffState, Magic_code); 2187 moxafunc(port->tableAddr, FC_SetXoffState, Magic_code);