aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorJiri Slaby <jirislaby@gmail.com>2007-02-10 04:45:08 -0500
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-02-11 13:51:28 -0500
commit44bafdf37b30234671d4e2fb595dea4c3717d089 (patch)
tree384306d2a82fa8fe553cefe0d63cd452d982ef1d /drivers
parent30a063a900518926966f4d75333c1bfbde1658fa (diff)
[PATCH] Char: serial167, cleanup
serial167, cleanup - Lindent the code - remove 3 pointers from paranoia_check Signed-off-by: Jiri Slaby <jirislaby@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/char/serial167.c3322
1 files changed, 1645 insertions, 1677 deletions
diff --git a/drivers/char/serial167.c b/drivers/char/serial167.c
index af50d32ae2c7..5fd314adc1f2 100644
--- a/drivers/char/serial167.c
+++ b/drivers/char/serial167.c
@@ -111,12 +111,13 @@ u_char initial_console_speed;
111 111
112/* This is the per-port data structure */ 112/* This is the per-port data structure */
113struct cyclades_port cy_port[] = { 113struct cyclades_port cy_port[] = {
114 /* CARD# */ 114 /* CARD# */
115 {-1 }, /* ttyS0 */ 115 {-1}, /* ttyS0 */
116 {-1 }, /* ttyS1 */ 116 {-1}, /* ttyS1 */
117 {-1 }, /* ttyS2 */ 117 {-1}, /* ttyS2 */
118 {-1 }, /* ttyS3 */ 118 {-1}, /* ttyS3 */
119}; 119};
120
120#define NR_PORTS ARRAY_SIZE(cy_port) 121#define NR_PORTS ARRAY_SIZE(cy_port)
121 122
122/* 123/*
@@ -128,42 +129,46 @@ struct cyclades_port cy_port[] = {
128 * HI VHI 129 * HI VHI
129 */ 130 */
130static int baud_table[] = { 131static int baud_table[] = {
131 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 132 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200,
132 1800, 2400, 4800, 9600, 19200, 38400, 57600, 76800,115200,150000, 133 1800, 2400, 4800, 9600, 19200, 38400, 57600, 76800, 115200, 150000,
133 0}; 134 0
135};
134 136
135#if 0 137#if 0
136static char baud_co[] = { /* 25 MHz clock option table */ 138static char baud_co[] = { /* 25 MHz clock option table */
137 /* value => 00 01 02 03 04 */ 139 /* value => 00 01 02 03 04 */
138 /* divide by 8 32 128 512 2048 */ 140 /* divide by 8 32 128 512 2048 */
139 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x02, 141 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x02,
140 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; 142 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
143};
141 144
142static char baud_bpr[] = { /* 25 MHz baud rate period table */ 145static char baud_bpr[] = { /* 25 MHz baud rate period table */
143 0x00, 0xf5, 0xa3, 0x6f, 0x5c, 0x51, 0xf5, 0xa3, 0x51, 0xa3, 146 0x00, 0xf5, 0xa3, 0x6f, 0x5c, 0x51, 0xf5, 0xa3, 0x51, 0xa3,
144 0x6d, 0x51, 0xa3, 0x51, 0xa3, 0x51, 0x36, 0x29, 0x1b, 0x15}; 147 0x6d, 0x51, 0xa3, 0x51, 0xa3, 0x51, 0x36, 0x29, 0x1b, 0x15
148};
145#endif 149#endif
146 150
147/* I think 166 brd clocks 2401 at 20MHz.... */ 151/* I think 166 brd clocks 2401 at 20MHz.... */
148 152
149/* These values are written directly to tcor, and >> 5 for writing to rcor */ 153/* These values are written directly to tcor, and >> 5 for writing to rcor */
150static u_char baud_co[] = { /* 20 MHz clock option table */ 154static u_char baud_co[] = { /* 20 MHz clock option table */
151 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x60, 0x60, 0x40, 155 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x60, 0x60, 0x40,
152 0x40, 0x40, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; 156 0x40, 0x40, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
157};
153 158
154/* These values written directly to tbpr/rbpr */ 159/* These values written directly to tbpr/rbpr */
155static u_char baud_bpr[] = { /* 20 MHz baud rate period table */ 160static u_char baud_bpr[] = { /* 20 MHz baud rate period table */
156 0x00, 0xc0, 0x80, 0x58, 0x6c, 0x40, 0xc0, 0x81, 0x40, 0x81, 161 0x00, 0xc0, 0x80, 0x58, 0x6c, 0x40, 0xc0, 0x81, 0x40, 0x81,
157 0x57, 0x40, 0x81, 0x40, 0x81, 0x40, 0x2b, 0x20, 0x15, 0x10}; 162 0x57, 0x40, 0x81, 0x40, 0x81, 0x40, 0x2b, 0x20, 0x15, 0x10
158 163};
159static u_char baud_cor4[] = { /* receive threshold */
160 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
161 0x0a, 0x0a, 0x0a, 0x09, 0x09, 0x08, 0x08, 0x08, 0x08, 0x07};
162
163 164
165static u_char baud_cor4[] = { /* receive threshold */
166 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
167 0x0a, 0x0a, 0x0a, 0x09, 0x09, 0x08, 0x08, 0x08, 0x08, 0x07
168};
164 169
165static void shutdown(struct cyclades_port *); 170static void shutdown(struct cyclades_port *);
166static int startup (struct cyclades_port *); 171static int startup(struct cyclades_port *);
167static void cy_throttle(struct tty_struct *); 172static void cy_throttle(struct tty_struct *);
168static void cy_unthrottle(struct tty_struct *); 173static void cy_unthrottle(struct tty_struct *);
169static void config_setup(struct cyclades_port *); 174static void config_setup(struct cyclades_port *);
@@ -174,16 +179,16 @@ static void show_status(int);
174 179
175#ifdef CONFIG_REMOTE_DEBUG 180#ifdef CONFIG_REMOTE_DEBUG
176static void debug_setup(void); 181static void debug_setup(void);
177void queueDebugChar (int c); 182void queueDebugChar(int c);
178int getDebugChar(void); 183int getDebugChar(void);
179 184
180#define DEBUG_PORT 1 185#define DEBUG_PORT 1
181#define DEBUG_LEN 256 186#define DEBUG_LEN 256
182 187
183typedef struct { 188typedef struct {
184 int in; 189 int in;
185 int out; 190 int out;
186 unsigned char buf[DEBUG_LEN]; 191 unsigned char buf[DEBUG_LEN];
187} debugq; 192} debugq;
188 193
189debugq debugiq; 194debugq debugiq;
@@ -196,7 +201,7 @@ debugq debugiq;
196 * delay, but this wild guess will do for now. 201 * delay, but this wild guess will do for now.
197 */ 202 */
198 203
199void my_udelay (long us) 204void my_udelay(long us)
200{ 205{
201 u_char x; 206 u_char x;
202 volatile u_char *p = &x; 207 volatile u_char *p = &x;
@@ -207,62 +212,73 @@ void my_udelay (long us)
207 x |= *p; 212 x |= *p;
208} 213}
209 214
210static inline int 215static inline int serial_paranoia_check(struct cyclades_port *info, char *name,
211serial_paranoia_check(struct cyclades_port *info, char *name, 216 const char *routine)
212 const char *routine)
213{ 217{
214#ifdef SERIAL_PARANOIA_CHECK 218#ifdef SERIAL_PARANOIA_CHECK
215 static const char *badmagic = 219 if (!info) {
216 "Warning: bad magic number for serial struct (%s) in %s\n"; 220 printk("Warning: null cyclades_port for (%s) in %s\n", name,
217 static const char *badinfo = 221 routine);
218 "Warning: null cyclades_port for (%s) in %s\n"; 222 return 1;
219 static const char *badrange = 223 }
220 "Warning: cyclades_port out of range for (%s) in %s\n"; 224
221 225 if ((long)info < (long)(&cy_port[0])
222 if (!info) { 226 || (long)(&cy_port[NR_PORTS]) < (long)info) {
223 printk(badinfo, name, routine); 227 printk("Warning: cyclades_port out of range for (%s) in %s\n",
224 return 1; 228 name, routine);
225 } 229 return 1;
226 230 }
227 if( (long)info < (long)(&cy_port[0]) 231
228 || (long)(&cy_port[NR_PORTS]) < (long)info ){ 232 if (info->magic != CYCLADES_MAGIC) {
229 printk(badrange, name, routine); 233 printk("Warning: bad magic number for serial struct (%s) in "
230 return 1; 234 "%s\n", name, routine);
231 } 235 return 1;
232 236 }
233 if (info->magic != CYCLADES_MAGIC) {
234 printk(badmagic, name, routine);
235 return 1;
236 }
237#endif 237#endif
238 return 0; 238 return 0;
239} /* serial_paranoia_check */ 239} /* serial_paranoia_check */
240 240
241#if 0 241#if 0
242/* The following diagnostic routines allow the driver to spew 242/* The following diagnostic routines allow the driver to spew
243 information on the screen, even (especially!) during interrupts. 243 information on the screen, even (especially!) during interrupts.
244 */ 244 */
245void 245void SP(char *data)
246SP(char *data){ 246{
247 unsigned long flags; 247 unsigned long flags;
248 local_irq_save(flags); 248 local_irq_save(flags);
249 console_print(data); 249 console_print(data);
250 local_irq_restore(flags); 250 local_irq_restore(flags);
251} 251}
252
252char scrn[2]; 253char scrn[2];
253void 254void CP(char data)
254CP(char data){ 255{
255 unsigned long flags; 256 unsigned long flags;
256 local_irq_save(flags); 257 local_irq_save(flags);
257 scrn[0] = data; 258 scrn[0] = data;
258 console_print(scrn); 259 console_print(scrn);
259 local_irq_restore(flags); 260 local_irq_restore(flags);
260}/* CP */ 261} /* CP */
261 262
262void CP1(int data) { (data<10)? CP(data+'0'): CP(data+'A'-10); }/* CP1 */ 263void CP1(int data)
263void CP2(int data) { CP1((data>>4) & 0x0f); CP1( data & 0x0f); }/* CP2 */ 264{
264void CP4(int data) { CP2((data>>8) & 0xff); CP2(data & 0xff); }/* CP4 */ 265 (data < 10) ? CP(data + '0') : CP(data + 'A' - 10);
265void CP8(long data) { CP4((data>>16) & 0xffff); CP4(data & 0xffff); }/* CP8 */ 266} /* CP1 */
267void CP2(int data)
268{
269 CP1((data >> 4) & 0x0f);
270 CP1(data & 0x0f);
271} /* CP2 */
272void CP4(int data)
273{
274 CP2((data >> 8) & 0xff);
275 CP2(data & 0xff);
276} /* CP4 */
277void CP8(long data)
278{
279 CP4((data >> 16) & 0xffff);
280 CP4(data & 0xffff);
281} /* CP8 */
266#endif 282#endif
267 283
268/* This routine waits up to 1000 micro-seconds for the previous 284/* This routine waits up to 1000 micro-seconds for the previous
@@ -270,87 +286,78 @@ void CP8(long data) { CP4((data>>16) & 0xffff); CP4(data & 0xffff); }/* CP8 */
270 new command. An error is returned if the previous command 286 new command. An error is returned if the previous command
271 didn't finish within the time limit. 287 didn't finish within the time limit.
272 */ 288 */
273u_short 289u_short write_cy_cmd(volatile u_char * base_addr, u_char cmd)
274write_cy_cmd(volatile u_char *base_addr, u_char cmd)
275{ 290{
276 unsigned long flags; 291 unsigned long flags;
277 volatile int i; 292 volatile int i;
278 293
279 local_irq_save(flags); 294 local_irq_save(flags);
280 /* Check to see that the previous command has completed */ 295 /* Check to see that the previous command has completed */
281 for(i = 0 ; i < 100 ; i++){ 296 for (i = 0; i < 100; i++) {
282 if (base_addr[CyCCR] == 0){ 297 if (base_addr[CyCCR] == 0) {
283 break; 298 break;
284 } 299 }
285 my_udelay(10L); 300 my_udelay(10L);
286 } 301 }
287 /* if the CCR never cleared, the previous command 302 /* if the CCR never cleared, the previous command
288 didn't finish within the "reasonable time" */ 303 didn't finish within the "reasonable time" */
289 if ( i == 10 ) { 304 if (i == 10) {
290 local_irq_restore(flags); 305 local_irq_restore(flags);
291 return (-1); 306 return (-1);
292 } 307 }
293 308
294 /* Issue the new command */ 309 /* Issue the new command */
295 base_addr[CyCCR] = cmd; 310 base_addr[CyCCR] = cmd;
296 local_irq_restore(flags); 311 local_irq_restore(flags);
297 return(0); 312 return (0);
298} /* write_cy_cmd */ 313} /* write_cy_cmd */
299
300 314
301/* cy_start and cy_stop provide software output flow control as a 315/* cy_start and cy_stop provide software output flow control as a
302 function of XON/XOFF, software CTS, and other such stuff. */ 316 function of XON/XOFF, software CTS, and other such stuff. */
303 317
304static void 318static void cy_stop(struct tty_struct *tty)
305cy_stop(struct tty_struct *tty)
306{ 319{
307 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 320 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
308 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR; 321 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
309 int channel; 322 int channel;
310 unsigned long flags; 323 unsigned long flags;
311 324
312#ifdef SERIAL_DEBUG_OTHER 325#ifdef SERIAL_DEBUG_OTHER
313 printk("cy_stop %s\n", tty->name); /* */ 326 printk("cy_stop %s\n", tty->name); /* */
314#endif 327#endif
315 328
316 if (serial_paranoia_check(info, tty->name, "cy_stop")) 329 if (serial_paranoia_check(info, tty->name, "cy_stop"))
317 return; 330 return;
318
319 channel = info->line;
320 331
321 local_irq_save(flags); 332 channel = info->line;
322 base_addr[CyCAR] = (u_char)(channel); /* index channel */
323 base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
324 local_irq_restore(flags);
325 333
326 return; 334 local_irq_save(flags);
327} /* cy_stop */ 335 base_addr[CyCAR] = (u_char) (channel); /* index channel */
336 base_addr[CyIER] &= ~(CyTxMpty | CyTxRdy);
337 local_irq_restore(flags);
338} /* cy_stop */
328 339
329static void 340static void cy_start(struct tty_struct *tty)
330cy_start(struct tty_struct *tty)
331{ 341{
332 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 342 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
333 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR; 343 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
334 int channel; 344 int channel;
335 unsigned long flags; 345 unsigned long flags;
336 346
337#ifdef SERIAL_DEBUG_OTHER 347#ifdef SERIAL_DEBUG_OTHER
338 printk("cy_start %s\n", tty->name); /* */ 348 printk("cy_start %s\n", tty->name); /* */
339#endif 349#endif
340 350
341 if (serial_paranoia_check(info, tty->name, "cy_start")) 351 if (serial_paranoia_check(info, tty->name, "cy_start"))
342 return; 352 return;
343
344 channel = info->line;
345 353
346 local_irq_save(flags); 354 channel = info->line;
347 base_addr[CyCAR] = (u_char)(channel);
348 base_addr[CyIER] |= CyTxMpty;
349 local_irq_restore(flags);
350
351 return;
352} /* cy_start */
353 355
356 local_irq_save(flags);
357 base_addr[CyCAR] = (u_char) (channel);
358 base_addr[CyIER] |= CyTxMpty;
359 local_irq_restore(flags);
360} /* cy_start */
354 361
355/* 362/*
356 * This routine is used by the interrupt handler to schedule 363 * This routine is used by the interrupt handler to schedule
@@ -358,332 +365,332 @@ cy_start(struct tty_struct *tty)
358 * (also known as the "bottom half"). This can be called any 365 * (also known as the "bottom half"). This can be called any
359 * number of times for any channel without harm. 366 * number of times for any channel without harm.
360 */ 367 */
361static inline void 368static inline void cy_sched_event(struct cyclades_port *info, int event)
362cy_sched_event(struct cyclades_port *info, int event)
363{ 369{
364 info->event |= 1 << event; /* remember what kind of event and who */ 370 info->event |= 1 << event; /* remember what kind of event and who */
365 schedule_work(&info->tqueue); 371 schedule_work(&info->tqueue);
366} /* cy_sched_event */ 372} /* cy_sched_event */
367
368 373
369/* The real interrupt service routines are called 374/* The real interrupt service routines are called
370 whenever the card wants its hand held--chars 375 whenever the card wants its hand held--chars
371 received, out buffer empty, modem change, etc. 376 received, out buffer empty, modem change, etc.
372 */ 377 */
373static irqreturn_t 378static irqreturn_t cd2401_rxerr_interrupt(int irq, void *dev_id)
374cd2401_rxerr_interrupt(int irq, void *dev_id)
375{ 379{
376 struct tty_struct *tty; 380 struct tty_struct *tty;
377 struct cyclades_port *info; 381 struct cyclades_port *info;
378 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR; 382 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
379 unsigned char err, rfoc; 383 unsigned char err, rfoc;
380 int channel; 384 int channel;
381 char data; 385 char data;
382 386
383 /* determine the channel and change to that context */ 387 /* determine the channel and change to that context */
384 channel = (u_short ) (base_addr[CyLICR] >> 2); 388 channel = (u_short) (base_addr[CyLICR] >> 2);
385 info = &cy_port[channel]; 389 info = &cy_port[channel];
386 info->last_active = jiffies; 390 info->last_active = jiffies;
387 391
388 if ((err = base_addr[CyRISR]) & CyTIMEOUT) { 392 if ((err = base_addr[CyRISR]) & CyTIMEOUT) {
389 /* This is a receive timeout interrupt, ignore it */ 393 /* This is a receive timeout interrupt, ignore it */
390 base_addr[CyREOIR] = CyNOTRANS; 394 base_addr[CyREOIR] = CyNOTRANS;
391 return IRQ_HANDLED; 395 return IRQ_HANDLED;
392 } 396 }
393
394 /* Read a byte of data if there is any - assume the error
395 * is associated with this character */
396 397
397 if ((rfoc = base_addr[CyRFOC]) != 0) 398 /* Read a byte of data if there is any - assume the error
398 data = base_addr[CyRDR]; 399 * is associated with this character */
399 else
400 data = 0;
401 400
402 /* if there is nowhere to put the data, discard it */ 401 if ((rfoc = base_addr[CyRFOC]) != 0)
403 if(info->tty == 0) { 402 data = base_addr[CyRDR];
403 else
404 data = 0;
405
406 /* if there is nowhere to put the data, discard it */
407 if (info->tty == 0) {
408 base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS;
409 return IRQ_HANDLED;
410 } else { /* there is an open port for this data */
411 tty = info->tty;
412 if (err & info->ignore_status_mask) {
413 base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS;
414 return IRQ_HANDLED;
415 }
416 if (tty_buffer_request_room(tty, 1) != 0) {
417 if (err & info->read_status_mask) {
418 if (err & CyBREAK) {
419 tty_insert_flip_char(tty, data,
420 TTY_BREAK);
421 if (info->flags & ASYNC_SAK) {
422 do_SAK(tty);
423 }
424 } else if (err & CyFRAME) {
425 tty_insert_flip_char(tty, data,
426 TTY_FRAME);
427 } else if (err & CyPARITY) {
428 tty_insert_flip_char(tty, data,
429 TTY_PARITY);
430 } else if (err & CyOVERRUN) {
431 tty_insert_flip_char(tty, 0,
432 TTY_OVERRUN);
433 /*
434 If the flip buffer itself is
435 overflowing, we still loose
436 the next incoming character.
437 */
438 if (tty_buffer_request_room(tty, 1) !=
439 0) {
440 tty_insert_flip_char(tty, data,
441 TTY_FRAME);
442 }
443 /* These two conditions may imply */
444 /* a normal read should be done. */
445 /* else if(data & CyTIMEOUT) */
446 /* else if(data & CySPECHAR) */
447 } else {
448 tty_insert_flip_char(tty, 0,
449 TTY_NORMAL);
450 }
451 } else {
452 tty_insert_flip_char(tty, data, TTY_NORMAL);
453 }
454 } else {
455 /* there was a software buffer overrun
456 and nothing could be done about it!!! */
457 }
458 }
459 tty_schedule_flip(tty);
460 /* end of service */
404 base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS; 461 base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS;
405 return IRQ_HANDLED; 462 return IRQ_HANDLED;
406 } 463} /* cy_rxerr_interrupt */
407 else { /* there is an open port for this data */ 464
408 tty = info->tty; 465static irqreturn_t cd2401_modem_interrupt(int irq, void *dev_id)
409 if(err & info->ignore_status_mask){
410 base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS;
411 return IRQ_HANDLED;
412 }
413 if (tty_buffer_request_room(tty, 1) != 0){
414 if (err & info->read_status_mask){
415 if(err & CyBREAK){
416 tty_insert_flip_char(tty, data, TTY_BREAK);
417 if (info->flags & ASYNC_SAK){
418 do_SAK(tty);
419 }
420 }else if(err & CyFRAME){
421 tty_insert_flip_char(tty, data, TTY_FRAME);
422 }else if(err & CyPARITY){
423 tty_insert_flip_char(tty, data, TTY_PARITY);
424 }else if(err & CyOVERRUN){
425 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
426 /*
427 If the flip buffer itself is
428 overflowing, we still loose
429 the next incoming character.
430 */
431 if (tty_buffer_request_room(tty, 1) != 0){
432 tty_insert_flip_char(tty, data, TTY_FRAME);
433 }
434 /* These two conditions may imply */
435 /* a normal read should be done. */
436 /* else if(data & CyTIMEOUT) */
437 /* else if(data & CySPECHAR) */
438 }else{
439 tty_insert_flip_char(tty, 0, TTY_NORMAL);
440 }
441 }else{
442 tty_insert_flip_char(tty, data, TTY_NORMAL);
443 }
444 }else{
445 /* there was a software buffer overrun
446 and nothing could be done about it!!! */
447 }
448 }
449 tty_schedule_flip(tty);
450 /* end of service */
451 base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS;
452 return IRQ_HANDLED;
453} /* cy_rxerr_interrupt */
454
455static irqreturn_t
456cd2401_modem_interrupt(int irq, void *dev_id)
457{ 466{
458 struct cyclades_port *info; 467 struct cyclades_port *info;
459 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR; 468 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
460 int channel; 469 int channel;
461 int mdm_change; 470 int mdm_change;
462 int mdm_status; 471 int mdm_status;
463 472
464 473 /* determine the channel and change to that context */
465 /* determine the channel and change to that context */ 474 channel = (u_short) (base_addr[CyLICR] >> 2);
466 channel = (u_short ) (base_addr[CyLICR] >> 2); 475 info = &cy_port[channel];
467 info = &cy_port[channel]; 476 info->last_active = jiffies;
468 info->last_active = jiffies; 477
469 478 mdm_change = base_addr[CyMISR];
470 mdm_change = base_addr[CyMISR]; 479 mdm_status = base_addr[CyMSVR1];
471 mdm_status = base_addr[CyMSVR1]; 480
472 481 if (info->tty == 0) { /* nowhere to put the data, ignore it */
473 if(info->tty == 0){ /* nowhere to put the data, ignore it */ 482 ;
474 ; 483 } else {
475 }else{ 484 if ((mdm_change & CyDCD)
476 if((mdm_change & CyDCD) 485 && (info->flags & ASYNC_CHECK_CD)) {
477 && (info->flags & ASYNC_CHECK_CD)){ 486 if (mdm_status & CyDCD) {
478 if(mdm_status & CyDCD){
479/* CP('!'); */ 487/* CP('!'); */
480 cy_sched_event(info, Cy_EVENT_OPEN_WAKEUP); 488 cy_sched_event(info, Cy_EVENT_OPEN_WAKEUP);
481 } else { 489 } else {
482/* CP('@'); */ 490/* CP('@'); */
483 cy_sched_event(info, Cy_EVENT_HANGUP); 491 cy_sched_event(info, Cy_EVENT_HANGUP);
484 } 492 }
485 }
486 if((mdm_change & CyCTS)
487 && (info->flags & ASYNC_CTS_FLOW)){
488 if(info->tty->stopped){
489 if(mdm_status & CyCTS){
490 /* !!! cy_start isn't used because... */
491 info->tty->stopped = 0;
492 base_addr[CyIER] |= CyTxMpty;
493 cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP);
494 } 493 }
495 }else{ 494 if ((mdm_change & CyCTS)
496 if(!(mdm_status & CyCTS)){ 495 && (info->flags & ASYNC_CTS_FLOW)) {
497 /* !!! cy_stop isn't used because... */ 496 if (info->tty->stopped) {
498 info->tty->stopped = 1; 497 if (mdm_status & CyCTS) {
499 base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy); 498 /* !!! cy_start isn't used because... */
499 info->tty->stopped = 0;
500 base_addr[CyIER] |= CyTxMpty;
501 cy_sched_event(info,
502 Cy_EVENT_WRITE_WAKEUP);
503 }
504 } else {
505 if (!(mdm_status & CyCTS)) {
506 /* !!! cy_stop isn't used because... */
507 info->tty->stopped = 1;
508 base_addr[CyIER] &=
509 ~(CyTxMpty | CyTxRdy);
510 }
511 }
512 }
513 if (mdm_status & CyDSR) {
500 } 514 }
501 }
502 }
503 if(mdm_status & CyDSR){
504 } 515 }
505 } 516 base_addr[CyMEOIR] = 0;
506 base_addr[CyMEOIR] = 0; 517 return IRQ_HANDLED;
507 return IRQ_HANDLED; 518} /* cy_modem_interrupt */
508} /* cy_modem_interrupt */
509 519
510static irqreturn_t 520static irqreturn_t cd2401_tx_interrupt(int irq, void *dev_id)
511cd2401_tx_interrupt(int irq, void *dev_id)
512{ 521{
513 struct cyclades_port *info; 522 struct cyclades_port *info;
514 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR; 523 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
515 int channel; 524 int channel;
516 int char_count, saved_cnt; 525 int char_count, saved_cnt;
517 int outch; 526 int outch;
518 527
519 /* determine the channel and change to that context */ 528 /* determine the channel and change to that context */
520 channel = (u_short ) (base_addr[CyLICR] >> 2); 529 channel = (u_short) (base_addr[CyLICR] >> 2);
521 530
522#ifdef CONFIG_REMOTE_DEBUG 531#ifdef CONFIG_REMOTE_DEBUG
523 if (channel == DEBUG_PORT) { 532 if (channel == DEBUG_PORT) {
524 panic ("TxInt on debug port!!!"); 533 panic("TxInt on debug port!!!");
525 } 534 }
526#endif 535#endif
527 536
528 info = &cy_port[channel]; 537 info = &cy_port[channel];
529 538
530 /* validate the port number (as configured and open) */ 539 /* validate the port number (as configured and open) */
531 if( (channel < 0) || (NR_PORTS <= channel) ){ 540 if ((channel < 0) || (NR_PORTS <= channel)) {
532 base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy); 541 base_addr[CyIER] &= ~(CyTxMpty | CyTxRdy);
533 base_addr[CyTEOIR] = CyNOTRANS; 542 base_addr[CyTEOIR] = CyNOTRANS;
534 return IRQ_HANDLED; 543 return IRQ_HANDLED;
535 } 544 }
536 info->last_active = jiffies; 545 info->last_active = jiffies;
537 if(info->tty == 0){ 546 if (info->tty == 0) {
538 base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy); 547 base_addr[CyIER] &= ~(CyTxMpty | CyTxRdy);
539 if (info->xmit_cnt < WAKEUP_CHARS) { 548 if (info->xmit_cnt < WAKEUP_CHARS) {
540 cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP); 549 cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP);
541 } 550 }
542 base_addr[CyTEOIR] = CyNOTRANS; 551 base_addr[CyTEOIR] = CyNOTRANS;
543 return IRQ_HANDLED; 552 return IRQ_HANDLED;
544 } 553 }
545 554
546 /* load the on-chip space available for outbound data */ 555 /* load the on-chip space available for outbound data */
547 saved_cnt = char_count = base_addr[CyTFTC]; 556 saved_cnt = char_count = base_addr[CyTFTC];
548 557
549 if(info->x_char) { /* send special char */ 558 if (info->x_char) { /* send special char */
550 outch = info->x_char; 559 outch = info->x_char;
551 base_addr[CyTDR] = outch;
552 char_count--;
553 info->x_char = 0;
554 }
555
556 if (info->x_break){
557 /* The Cirrus chip requires the "Embedded Transmit
558 Commands" of start break, delay, and end break
559 sequences to be sent. The duration of the
560 break is given in TICs, which runs at HZ
561 (typically 100) and the PPR runs at 200 Hz,
562 so the delay is duration * 200/HZ, and thus a
563 break can run from 1/100 sec to about 5/4 sec.
564 Need to check these values - RGH 141095.
565 */
566 base_addr[CyTDR] = 0; /* start break */
567 base_addr[CyTDR] = 0x81;
568 base_addr[CyTDR] = 0; /* delay a bit */
569 base_addr[CyTDR] = 0x82;
570 base_addr[CyTDR] = info->x_break*200/HZ;
571 base_addr[CyTDR] = 0; /* terminate break */
572 base_addr[CyTDR] = 0x83;
573 char_count -= 7;
574 info->x_break = 0;
575 }
576
577 while (char_count > 0){
578 if (!info->xmit_cnt){
579 base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
580 break;
581 }
582 if (info->xmit_buf == 0){
583 base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
584 break;
585 }
586 if (info->tty->stopped || info->tty->hw_stopped){
587 base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
588 break;
589 }
590 /* Because the Embedded Transmit Commands have been
591 enabled, we must check to see if the escape
592 character, NULL, is being sent. If it is, we
593 must ensure that there is room for it to be
594 doubled in the output stream. Therefore we
595 no longer advance the pointer when the character
596 is fetched, but rather wait until after the check
597 for a NULL output character. (This is necessary
598 because there may not be room for the two chars
599 needed to send a NULL.
600 */
601 outch = info->xmit_buf[info->xmit_tail];
602 if( outch ){
603 info->xmit_cnt--;
604 info->xmit_tail = (info->xmit_tail + 1)
605 & (PAGE_SIZE - 1);
606 base_addr[CyTDR] = outch;
607 char_count--;
608 }else{
609 if(char_count > 1){
610 info->xmit_cnt--;
611 info->xmit_tail = (info->xmit_tail + 1)
612 & (PAGE_SIZE - 1);
613 base_addr[CyTDR] = outch; 560 base_addr[CyTDR] = outch;
614 base_addr[CyTDR] = 0;
615 char_count--; 561 char_count--;
616 char_count--; 562 info->x_char = 0;
617 }else{
618 break;
619 }
620 } 563 }
621 }
622 564
623 if (info->xmit_cnt < WAKEUP_CHARS) { 565 if (info->x_break) {
624 cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP); 566 /* The Cirrus chip requires the "Embedded Transmit
625 } 567 Commands" of start break, delay, and end break
626 base_addr[CyTEOIR] = (char_count != saved_cnt) ? 0 : CyNOTRANS; 568 sequences to be sent. The duration of the
627 return IRQ_HANDLED; 569 break is given in TICs, which runs at HZ
628} /* cy_tx_interrupt */ 570 (typically 100) and the PPR runs at 200 Hz,
571 so the delay is duration * 200/HZ, and thus a
572 break can run from 1/100 sec to about 5/4 sec.
573 Need to check these values - RGH 141095.
574 */
575 base_addr[CyTDR] = 0; /* start break */
576 base_addr[CyTDR] = 0x81;
577 base_addr[CyTDR] = 0; /* delay a bit */
578 base_addr[CyTDR] = 0x82;
579 base_addr[CyTDR] = info->x_break * 200 / HZ;
580 base_addr[CyTDR] = 0; /* terminate break */
581 base_addr[CyTDR] = 0x83;
582 char_count -= 7;
583 info->x_break = 0;
584 }
585
586 while (char_count > 0) {
587 if (!info->xmit_cnt) {
588 base_addr[CyIER] &= ~(CyTxMpty | CyTxRdy);
589 break;
590 }
591 if (info->xmit_buf == 0) {
592 base_addr[CyIER] &= ~(CyTxMpty | CyTxRdy);
593 break;
594 }
595 if (info->tty->stopped || info->tty->hw_stopped) {
596 base_addr[CyIER] &= ~(CyTxMpty | CyTxRdy);
597 break;
598 }
599 /* Because the Embedded Transmit Commands have been
600 enabled, we must check to see if the escape
601 character, NULL, is being sent. If it is, we
602 must ensure that there is room for it to be
603 doubled in the output stream. Therefore we
604 no longer advance the pointer when the character
605 is fetched, but rather wait until after the check
606 for a NULL output character. (This is necessary
607 because there may not be room for the two chars
608 needed to send a NULL.
609 */
610 outch = info->xmit_buf[info->xmit_tail];
611 if (outch) {
612 info->xmit_cnt--;
613 info->xmit_tail = (info->xmit_tail + 1)
614 & (PAGE_SIZE - 1);
615 base_addr[CyTDR] = outch;
616 char_count--;
617 } else {
618 if (char_count > 1) {
619 info->xmit_cnt--;
620 info->xmit_tail = (info->xmit_tail + 1)
621 & (PAGE_SIZE - 1);
622 base_addr[CyTDR] = outch;
623 base_addr[CyTDR] = 0;
624 char_count--;
625 char_count--;
626 } else {
627 break;
628 }
629 }
630 }
631
632 if (info->xmit_cnt < WAKEUP_CHARS) {
633 cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP);
634 }
635 base_addr[CyTEOIR] = (char_count != saved_cnt) ? 0 : CyNOTRANS;
636 return IRQ_HANDLED;
637} /* cy_tx_interrupt */
629 638
630static irqreturn_t 639static irqreturn_t cd2401_rx_interrupt(int irq, void *dev_id)
631cd2401_rx_interrupt(int irq, void *dev_id)
632{ 640{
633 struct tty_struct *tty; 641 struct tty_struct *tty;
634 struct cyclades_port *info; 642 struct cyclades_port *info;
635 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR; 643 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
636 int channel; 644 int channel;
637 char data; 645 char data;
638 int char_count; 646 int char_count;
639 int save_cnt; 647 int save_cnt;
640 int len; 648 int len;
641 649
642 /* determine the channel and change to that context */ 650 /* determine the channel and change to that context */
643 channel = (u_short ) (base_addr[CyLICR] >> 2); 651 channel = (u_short) (base_addr[CyLICR] >> 2);
644 info = &cy_port[channel]; 652 info = &cy_port[channel];
645 info->last_active = jiffies; 653 info->last_active = jiffies;
646 save_cnt = char_count = base_addr[CyRFOC]; 654 save_cnt = char_count = base_addr[CyRFOC];
647 655
648#ifdef CONFIG_REMOTE_DEBUG 656#ifdef CONFIG_REMOTE_DEBUG
649 if (channel == DEBUG_PORT) { 657 if (channel == DEBUG_PORT) {
650 while (char_count--) { 658 while (char_count--) {
651 data = base_addr[CyRDR]; 659 data = base_addr[CyRDR];
652 queueDebugChar(data); 660 queueDebugChar(data);
653 } 661 }
654 } 662 } else
655 else
656#endif 663#endif
657 /* if there is nowhere to put the data, discard it */ 664 /* if there is nowhere to put the data, discard it */
658 if(info->tty == 0){ 665 if (info->tty == 0) {
659 while(char_count--){ 666 while (char_count--) {
660 data = base_addr[CyRDR]; 667 data = base_addr[CyRDR];
661 } 668 }
662 }else{ /* there is an open port for this data */ 669 } else { /* there is an open port for this data */
663 tty = info->tty; 670 tty = info->tty;
664 /* load # characters available from the chip */ 671 /* load # characters available from the chip */
665 672
666#ifdef CYCLOM_ENABLE_MONITORING 673#ifdef CYCLOM_ENABLE_MONITORING
667 ++info->mon.int_count; 674 ++info->mon.int_count;
668 info->mon.char_count += char_count; 675 info->mon.char_count += char_count;
669 if (char_count > info->mon.char_max) 676 if (char_count > info->mon.char_max)
670 info->mon.char_max = char_count; 677 info->mon.char_max = char_count;
671 info->mon.char_last = char_count; 678 info->mon.char_last = char_count;
672#endif 679#endif
673 len = tty_buffer_request_room(tty, char_count); 680 len = tty_buffer_request_room(tty, char_count);
674 while(len--){ 681 while (len--) {
675 data = base_addr[CyRDR]; 682 data = base_addr[CyRDR];
676 tty_insert_flip_char(tty, data, TTY_NORMAL); 683 tty_insert_flip_char(tty, data, TTY_NORMAL);
677#ifdef CYCLOM_16Y_HACK 684#ifdef CYCLOM_16Y_HACK
678 udelay(10L); 685 udelay(10L);
679#endif 686#endif
680 } 687 }
681 tty_schedule_flip(tty); 688 tty_schedule_flip(tty);
682 } 689 }
683 /* end of service */ 690 /* end of service */
684 base_addr[CyREOIR] = save_cnt ? 0 : CyNOTRANS; 691 base_addr[CyREOIR] = save_cnt ? 0 : CyNOTRANS;
685 return IRQ_HANDLED; 692 return IRQ_HANDLED;
686} /* cy_rx_interrupt */ 693} /* cy_rx_interrupt */
687 694
688/* 695/*
689 * This routine is used to handle the "bottom half" processing for the 696 * This routine is used to handle the "bottom half" processing for the
@@ -705,192 +712,188 @@ cd2401_rx_interrupt(int irq, void *dev_id)
705 * structure) to the bottom half of the driver. Previous kernels 712 * structure) to the bottom half of the driver. Previous kernels
706 * had to poll every port to see if that port needed servicing. 713 * had to poll every port to see if that port needed servicing.
707 */ 714 */
708static void 715static void do_softint(struct work_struct *ugly_api)
709do_softint(struct work_struct *ugly_api)
710{ 716{
711 struct cyclades_port *info = container_of(ugly_api, struct cyclades_port, tqueue); 717 struct cyclades_port *info =
712 struct tty_struct *tty; 718 container_of(ugly_api, struct cyclades_port, tqueue);
713 719 struct tty_struct *tty;
714 tty = info->tty;
715 if (!tty)
716 return;
717 720
718 if (test_and_clear_bit(Cy_EVENT_HANGUP, &info->event)) { 721 tty = info->tty;
719 tty_hangup(info->tty); 722 if (!tty)
720 wake_up_interruptible(&info->open_wait); 723 return;
721 info->flags &= ~ASYNC_NORMAL_ACTIVE;
722 }
723 if (test_and_clear_bit(Cy_EVENT_OPEN_WAKEUP, &info->event)) {
724 wake_up_interruptible(&info->open_wait);
725 }
726 if (test_and_clear_bit(Cy_EVENT_WRITE_WAKEUP, &info->event)) {
727 tty_wakeup(tty);
728 }
729} /* do_softint */
730 724
725 if (test_and_clear_bit(Cy_EVENT_HANGUP, &info->event)) {
726 tty_hangup(info->tty);
727 wake_up_interruptible(&info->open_wait);
728 info->flags &= ~ASYNC_NORMAL_ACTIVE;
729 }
730 if (test_and_clear_bit(Cy_EVENT_OPEN_WAKEUP, &info->event)) {
731 wake_up_interruptible(&info->open_wait);
732 }
733 if (test_and_clear_bit(Cy_EVENT_WRITE_WAKEUP, &info->event)) {
734 tty_wakeup(tty);
735 }
736} /* do_softint */
731 737
732/* This is called whenever a port becomes active; 738/* This is called whenever a port becomes active;
733 interrupts are enabled and DTR & RTS are turned on. 739 interrupts are enabled and DTR & RTS are turned on.
734 */ 740 */
735static int 741static int startup(struct cyclades_port *info)
736startup(struct cyclades_port * info)
737{ 742{
738 unsigned long flags; 743 unsigned long flags;
739 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR; 744 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
740 int channel; 745 int channel;
741 746
742 if (info->flags & ASYNC_INITIALIZED){ 747 if (info->flags & ASYNC_INITIALIZED) {
743 return 0; 748 return 0;
744 } 749 }
745 750
746 if (!info->type){ 751 if (!info->type) {
747 if (info->tty){ 752 if (info->tty) {
748 set_bit(TTY_IO_ERROR, &info->tty->flags); 753 set_bit(TTY_IO_ERROR, &info->tty->flags);
754 }
755 return 0;
749 } 756 }
750 return 0; 757 if (!info->xmit_buf) {
751 } 758 info->xmit_buf = (unsigned char *)get_zeroed_page(GFP_KERNEL);
752 if (!info->xmit_buf){ 759 if (!info->xmit_buf) {
753 info->xmit_buf = (unsigned char *) get_zeroed_page (GFP_KERNEL); 760 return -ENOMEM;
754 if (!info->xmit_buf){ 761 }
755 return -ENOMEM;
756 } 762 }
757 }
758 763
759 config_setup(info); 764 config_setup(info);
760 765
761 channel = info->line; 766 channel = info->line;
762 767
763#ifdef SERIAL_DEBUG_OPEN 768#ifdef SERIAL_DEBUG_OPEN
764 printk("startup channel %d\n", channel); 769 printk("startup channel %d\n", channel);
765#endif 770#endif
766 771
767 local_irq_save(flags); 772 local_irq_save(flags);
768 base_addr[CyCAR] = (u_char)channel; 773 base_addr[CyCAR] = (u_char) channel;
769 write_cy_cmd(base_addr,CyENB_RCVR|CyENB_XMTR); 774 write_cy_cmd(base_addr, CyENB_RCVR | CyENB_XMTR);
770 775
771 base_addr[CyCAR] = (u_char)channel; /* !!! Is this needed? */ 776 base_addr[CyCAR] = (u_char) channel; /* !!! Is this needed? */
772 base_addr[CyMSVR1] = CyRTS; 777 base_addr[CyMSVR1] = CyRTS;
773/* CP('S');CP('1'); */ 778/* CP('S');CP('1'); */
774 base_addr[CyMSVR2] = CyDTR; 779 base_addr[CyMSVR2] = CyDTR;
775 780
776#ifdef SERIAL_DEBUG_DTR 781#ifdef SERIAL_DEBUG_DTR
777 printk("cyc: %d: raising DTR\n", __LINE__); 782 printk("cyc: %d: raising DTR\n", __LINE__);
778 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]); 783 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1],
784 base_addr[CyMSVR2]);
779#endif 785#endif
780 786
781 base_addr[CyIER] |= CyRxData; 787 base_addr[CyIER] |= CyRxData;
782 info->flags |= ASYNC_INITIALIZED; 788 info->flags |= ASYNC_INITIALIZED;
783 789
784 if (info->tty){ 790 if (info->tty) {
785 clear_bit(TTY_IO_ERROR, &info->tty->flags); 791 clear_bit(TTY_IO_ERROR, &info->tty->flags);
786 } 792 }
787 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0; 793 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
788 794
789 local_irq_restore(flags); 795 local_irq_restore(flags);
790 796
791#ifdef SERIAL_DEBUG_OPEN 797#ifdef SERIAL_DEBUG_OPEN
792 printk(" done\n"); 798 printk(" done\n");
793#endif 799#endif
794 return 0; 800 return 0;
795} /* startup */ 801} /* startup */
796 802
797void 803void start_xmit(struct cyclades_port *info)
798start_xmit( struct cyclades_port *info )
799{ 804{
800 unsigned long flags; 805 unsigned long flags;
801 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 806 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
802 int channel; 807 int channel;
803 808
804 channel = info->line; 809 channel = info->line;
805 local_irq_save(flags); 810 local_irq_save(flags);
806 base_addr[CyCAR] = channel; 811 base_addr[CyCAR] = channel;
807 base_addr[CyIER] |= CyTxMpty; 812 base_addr[CyIER] |= CyTxMpty;
808 local_irq_restore(flags); 813 local_irq_restore(flags);
809} /* start_xmit */ 814} /* start_xmit */
810 815
811/* 816/*
812 * This routine shuts down a serial port; interrupts are disabled, 817 * This routine shuts down a serial port; interrupts are disabled,
813 * and DTR is dropped if the hangup on close termio flag is on. 818 * and DTR is dropped if the hangup on close termio flag is on.
814 */ 819 */
815static void 820static void shutdown(struct cyclades_port *info)
816shutdown(struct cyclades_port * info)
817{ 821{
818 unsigned long flags; 822 unsigned long flags;
819 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 823 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
820 int channel; 824 int channel;
821 825
822 if (!(info->flags & ASYNC_INITIALIZED)){ 826 if (!(info->flags & ASYNC_INITIALIZED)) {
823/* CP('$'); */ 827/* CP('$'); */
824 return; 828 return;
825 } 829 }
826 830
827 channel = info->line; 831 channel = info->line;
828 832
829#ifdef SERIAL_DEBUG_OPEN 833#ifdef SERIAL_DEBUG_OPEN
830 printk("shutdown channel %d\n", channel); 834 printk("shutdown channel %d\n", channel);
831#endif 835#endif
832 836
833 /* !!! REALLY MUST WAIT FOR LAST CHARACTER TO BE 837 /* !!! REALLY MUST WAIT FOR LAST CHARACTER TO BE
834 SENT BEFORE DROPPING THE LINE !!! (Perhaps 838 SENT BEFORE DROPPING THE LINE !!! (Perhaps
835 set some flag that is read when XMTY happens.) 839 set some flag that is read when XMTY happens.)
836 Other choices are to delay some fixed interval 840 Other choices are to delay some fixed interval
837 or schedule some later processing. 841 or schedule some later processing.
838 */ 842 */
839 local_irq_save(flags); 843 local_irq_save(flags);
840 if (info->xmit_buf){ 844 if (info->xmit_buf) {
841 free_page((unsigned long) info->xmit_buf); 845 free_page((unsigned long)info->xmit_buf);
842 info->xmit_buf = NULL; 846 info->xmit_buf = NULL;
843 } 847 }
844 848
845 base_addr[CyCAR] = (u_char)channel; 849 base_addr[CyCAR] = (u_char) channel;
846 if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) { 850 if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) {
847 base_addr[CyMSVR1] = 0; 851 base_addr[CyMSVR1] = 0;
848/* CP('C');CP('1'); */ 852/* CP('C');CP('1'); */
849 base_addr[CyMSVR2] = 0; 853 base_addr[CyMSVR2] = 0;
850#ifdef SERIAL_DEBUG_DTR 854#ifdef SERIAL_DEBUG_DTR
851 printk("cyc: %d: dropping DTR\n", __LINE__); 855 printk("cyc: %d: dropping DTR\n", __LINE__);
852 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]); 856 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1],
857 base_addr[CyMSVR2]);
853#endif 858#endif
854 } 859 }
855 write_cy_cmd(base_addr,CyDIS_RCVR); 860 write_cy_cmd(base_addr, CyDIS_RCVR);
856 /* it may be appropriate to clear _XMIT at 861 /* it may be appropriate to clear _XMIT at
857 some later date (after testing)!!! */ 862 some later date (after testing)!!! */
858 863
859 if (info->tty){ 864 if (info->tty) {
860 set_bit(TTY_IO_ERROR, &info->tty->flags); 865 set_bit(TTY_IO_ERROR, &info->tty->flags);
861 } 866 }
862 info->flags &= ~ASYNC_INITIALIZED; 867 info->flags &= ~ASYNC_INITIALIZED;
863 local_irq_restore(flags); 868 local_irq_restore(flags);
864 869
865#ifdef SERIAL_DEBUG_OPEN 870#ifdef SERIAL_DEBUG_OPEN
866 printk(" done\n"); 871 printk(" done\n");
867#endif 872#endif
868 return; 873} /* shutdown */
869} /* shutdown */
870 874
871/* 875/*
872 * This routine finds or computes the various line characteristics. 876 * This routine finds or computes the various line characteristics.
873 */ 877 */
874static void 878static void config_setup(struct cyclades_port *info)
875config_setup(struct cyclades_port * info)
876{ 879{
877 unsigned long flags; 880 unsigned long flags;
878 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 881 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
879 int channel; 882 int channel;
880 unsigned cflag; 883 unsigned cflag;
881 int i; 884 int i;
882 unsigned char ti, need_init_chan = 0; 885 unsigned char ti, need_init_chan = 0;
883 886
884 if (!info->tty || !info->tty->termios){ 887 if (!info->tty || !info->tty->termios) {
885 return; 888 return;
886 } 889 }
887 if (info->line == -1){ 890 if (info->line == -1) {
888 return; 891 return;
889 } 892 }
890 cflag = info->tty->termios->c_cflag; 893 cflag = info->tty->termios->c_cflag;
891 894
892 /* baud rate */ 895 /* baud rate */
893 i = cflag & CBAUD; 896 i = cflag & CBAUD;
894#ifdef CBAUDEX 897#ifdef CBAUDEX
895/* Starting with kernel 1.1.65, there is direct support for 898/* Starting with kernel 1.1.65, there is direct support for
896 higher baud rates. The following code supports those 899 higher baud rates. The following code supports those
@@ -900,120 +903,123 @@ config_setup(struct cyclades_port * info)
900 is still the possibility of supporting 75 kbit/sec with 903 is still the possibility of supporting 75 kbit/sec with
901 the Cyclades board.) 904 the Cyclades board.)
902 */ 905 */
903 if (i & CBAUDEX) { 906 if (i & CBAUDEX) {
904 if (i == B57600) 907 if (i == B57600)
905 i = 16; 908 i = 16;
906 else if(i == B115200) 909 else if (i == B115200)
907 i = 18; 910 i = 18;
908#ifdef B78600 911#ifdef B78600
909 else if(i == B78600) 912 else if (i == B78600)
910 i = 17; 913 i = 17;
911#endif 914#endif
912 else 915 else
913 info->tty->termios->c_cflag &= ~CBAUDEX; 916 info->tty->termios->c_cflag &= ~CBAUDEX;
914 } 917 }
915#endif 918#endif
916 if (i == 15) { 919 if (i == 15) {
917 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI) 920 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
918 i += 1; 921 i += 1;
919 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI) 922 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
920 i += 3; 923 i += 3;
921 } 924 }
922 /* Don't ever change the speed of the console port. It will 925 /* Don't ever change the speed of the console port. It will
923 * run at the speed specified in bootinfo, or at 19.2K */ 926 * run at the speed specified in bootinfo, or at 19.2K */
924 /* Actually, it should run at whatever speed 166Bug was using */ 927 /* Actually, it should run at whatever speed 166Bug was using */
925 /* Note info->timeout isn't used at present */ 928 /* Note info->timeout isn't used at present */
926 if (info != serial_console_info) { 929 if (info != serial_console_info) {
927 info->tbpr = baud_bpr[i]; /* Tx BPR */ 930 info->tbpr = baud_bpr[i]; /* Tx BPR */
928 info->tco = baud_co[i]; /* Tx CO */ 931 info->tco = baud_co[i]; /* Tx CO */
929 info->rbpr = baud_bpr[i]; /* Rx BPR */ 932 info->rbpr = baud_bpr[i]; /* Rx BPR */
930 info->rco = baud_co[i] >> 5; /* Rx CO */ 933 info->rco = baud_co[i] >> 5; /* Rx CO */
931 if (baud_table[i] == 134) { 934 if (baud_table[i] == 134) {
932 info->timeout = (info->xmit_fifo_size*HZ*30/269) + 2; 935 info->timeout =
933 /* get it right for 134.5 baud */ 936 (info->xmit_fifo_size * HZ * 30 / 269) + 2;
934 } else if (baud_table[i]) { 937 /* get it right for 134.5 baud */
935 info->timeout = (info->xmit_fifo_size*HZ*15/baud_table[i]) + 2; 938 } else if (baud_table[i]) {
936 /* this needs to be propagated into the card info */ 939 info->timeout =
940 (info->xmit_fifo_size * HZ * 15 / baud_table[i]) +
941 2;
942 /* this needs to be propagated into the card info */
943 } else {
944 info->timeout = 0;
945 }
946 }
947 /* By tradition (is it a standard?) a baud rate of zero
948 implies the line should be/has been closed. A bit
949 later in this routine such a test is performed. */
950
951 /* byte size and parity */
952 info->cor7 = 0;
953 info->cor6 = 0;
954 info->cor5 = 0;
955 info->cor4 = (info->default_threshold ? info->default_threshold : baud_cor4[i]); /* receive threshold */
956 /* Following two lines added 101295, RGH. */
957 /* It is obviously wrong to access CyCORx, and not info->corx here,
958 * try and remember to fix it later! */
959 channel = info->line;
960 base_addr[CyCAR] = (u_char) channel;
961 if (C_CLOCAL(info->tty)) {
962 if (base_addr[CyIER] & CyMdmCh)
963 base_addr[CyIER] &= ~CyMdmCh; /* without modem intr */
964 /* ignore 1->0 modem transitions */
965 if (base_addr[CyCOR4] & (CyDSR | CyCTS | CyDCD))
966 base_addr[CyCOR4] &= ~(CyDSR | CyCTS | CyDCD);
967 /* ignore 0->1 modem transitions */
968 if (base_addr[CyCOR5] & (CyDSR | CyCTS | CyDCD))
969 base_addr[CyCOR5] &= ~(CyDSR | CyCTS | CyDCD);
937 } else { 970 } else {
938 info->timeout = 0; 971 if ((base_addr[CyIER] & CyMdmCh) != CyMdmCh)
939 } 972 base_addr[CyIER] |= CyMdmCh; /* with modem intr */
940 } 973 /* act on 1->0 modem transitions */
941 /* By tradition (is it a standard?) a baud rate of zero 974 if ((base_addr[CyCOR4] & (CyDSR | CyCTS | CyDCD)) !=
942 implies the line should be/has been closed. A bit 975 (CyDSR | CyCTS | CyDCD))
943 later in this routine such a test is performed. */ 976 base_addr[CyCOR4] |= CyDSR | CyCTS | CyDCD;
944 977 /* act on 0->1 modem transitions */
945 /* byte size and parity */ 978 if ((base_addr[CyCOR5] & (CyDSR | CyCTS | CyDCD)) !=
946 info->cor7 = 0; 979 (CyDSR | CyCTS | CyDCD))
947 info->cor6 = 0; 980 base_addr[CyCOR5] |= CyDSR | CyCTS | CyDCD;
948 info->cor5 = 0; 981 }
949 info->cor4 = (info->default_threshold 982 info->cor3 = (cflag & CSTOPB) ? Cy_2_STOP : Cy_1_STOP;
950 ? info->default_threshold 983 info->cor2 = CyETC;
951 : baud_cor4[i]); /* receive threshold */ 984 switch (cflag & CSIZE) {
952 /* Following two lines added 101295, RGH. */ 985 case CS5:
953 /* It is obviously wrong to access CyCORx, and not info->corx here, 986 info->cor1 = Cy_5_BITS;
954 * try and remember to fix it later! */ 987 break;
955 channel = info->line; 988 case CS6:
956 base_addr[CyCAR] = (u_char)channel; 989 info->cor1 = Cy_6_BITS;
957 if (C_CLOCAL(info->tty)) { 990 break;
958 if (base_addr[CyIER] & CyMdmCh) 991 case CS7:
959 base_addr[CyIER] &= ~CyMdmCh; /* without modem intr */ 992 info->cor1 = Cy_7_BITS;
960 /* ignore 1->0 modem transitions */ 993 break;
961 if (base_addr[CyCOR4] & (CyDSR|CyCTS|CyDCD)) 994 case CS8:
962 base_addr[CyCOR4] &= ~(CyDSR|CyCTS|CyDCD); 995 info->cor1 = Cy_8_BITS;
963 /* ignore 0->1 modem transitions */ 996 break;
964 if (base_addr[CyCOR5] & (CyDSR|CyCTS|CyDCD)) 997 }
965 base_addr[CyCOR5] &= ~(CyDSR|CyCTS|CyDCD); 998 if (cflag & PARENB) {
966 } else { 999 if (cflag & PARODD) {
967 if ((base_addr[CyIER] & CyMdmCh) != CyMdmCh) 1000 info->cor1 |= CyPARITY_O;
968 base_addr[CyIER] |= CyMdmCh; /* with modem intr */ 1001 } else {
969 /* act on 1->0 modem transitions */ 1002 info->cor1 |= CyPARITY_E;
970 if ((base_addr[CyCOR4] & (CyDSR|CyCTS|CyDCD)) != (CyDSR|CyCTS|CyDCD)) 1003 }
971 base_addr[CyCOR4] |= CyDSR|CyCTS|CyDCD; 1004 } else {
972 /* act on 0->1 modem transitions */ 1005 info->cor1 |= CyPARITY_NONE;
973 if ((base_addr[CyCOR5] & (CyDSR|CyCTS|CyDCD)) != (CyDSR|CyCTS|CyDCD)) 1006 }
974 base_addr[CyCOR5] |= CyDSR|CyCTS|CyDCD; 1007
975 } 1008 /* CTS flow control flag */
976 info->cor3 = (cflag & CSTOPB) ? Cy_2_STOP : Cy_1_STOP;
977 info->cor2 = CyETC;
978 switch(cflag & CSIZE){
979 case CS5:
980 info->cor1 = Cy_5_BITS;
981 break;
982 case CS6:
983 info->cor1 = Cy_6_BITS;
984 break;
985 case CS7:
986 info->cor1 = Cy_7_BITS;
987 break;
988 case CS8:
989 info->cor1 = Cy_8_BITS;
990 break;
991 }
992 if (cflag & PARENB){
993 if (cflag & PARODD){
994 info->cor1 |= CyPARITY_O;
995 }else{
996 info->cor1 |= CyPARITY_E;
997 }
998 }else{
999 info->cor1 |= CyPARITY_NONE;
1000 }
1001
1002 /* CTS flow control flag */
1003#if 0 1009#if 0
1004 /* Don't complcate matters for now! RGH 141095 */ 1010 /* Don't complcate matters for now! RGH 141095 */
1005 if (cflag & CRTSCTS){ 1011 if (cflag & CRTSCTS) {
1006 info->flags |= ASYNC_CTS_FLOW; 1012 info->flags |= ASYNC_CTS_FLOW;
1007 info->cor2 |= CyCtsAE; 1013 info->cor2 |= CyCtsAE;
1008 }else{ 1014 } else {
1009 info->flags &= ~ASYNC_CTS_FLOW; 1015 info->flags &= ~ASYNC_CTS_FLOW;
1010 info->cor2 &= ~CyCtsAE; 1016 info->cor2 &= ~CyCtsAE;
1011 } 1017 }
1012#endif 1018#endif
1013 if (cflag & CLOCAL) 1019 if (cflag & CLOCAL)
1014 info->flags &= ~ASYNC_CHECK_CD; 1020 info->flags &= ~ASYNC_CHECK_CD;
1015 else 1021 else
1016 info->flags |= ASYNC_CHECK_CD; 1022 info->flags |= ASYNC_CHECK_CD;
1017 1023
1018 /*********************************************** 1024 /***********************************************
1019 The hardware option, CyRtsAO, presents RTS when 1025 The hardware option, CyRtsAO, presents RTS when
@@ -1025,149 +1031,146 @@ config_setup(struct cyclades_port * info)
1025 cable. Contact Marcio Saito for details. 1031 cable. Contact Marcio Saito for details.
1026 ***********************************************/ 1032 ***********************************************/
1027 1033
1028 channel = info->line; 1034 channel = info->line;
1029 1035
1030 local_irq_save(flags); 1036 local_irq_save(flags);
1031 base_addr[CyCAR] = (u_char)channel; 1037 base_addr[CyCAR] = (u_char) channel;
1032 1038
1033 /* CyCMR set once only in mvme167_init_serial() */ 1039 /* CyCMR set once only in mvme167_init_serial() */
1034 if (base_addr[CyLICR] != channel << 2) 1040 if (base_addr[CyLICR] != channel << 2)
1035 base_addr[CyLICR] = channel << 2; 1041 base_addr[CyLICR] = channel << 2;
1036 if (base_addr[CyLIVR] != 0x5c) 1042 if (base_addr[CyLIVR] != 0x5c)
1037 base_addr[CyLIVR] = 0x5c; 1043 base_addr[CyLIVR] = 0x5c;
1038 1044
1039 /* tx and rx baud rate */ 1045 /* tx and rx baud rate */
1040 1046
1041 if (base_addr[CyCOR1] != info->cor1) 1047 if (base_addr[CyCOR1] != info->cor1)
1042 need_init_chan = 1; 1048 need_init_chan = 1;
1043 if (base_addr[CyTCOR] != info->tco) 1049 if (base_addr[CyTCOR] != info->tco)
1044 base_addr[CyTCOR] = info->tco; 1050 base_addr[CyTCOR] = info->tco;
1045 if (base_addr[CyTBPR] != info->tbpr) 1051 if (base_addr[CyTBPR] != info->tbpr)
1046 base_addr[CyTBPR] = info->tbpr; 1052 base_addr[CyTBPR] = info->tbpr;
1047 if (base_addr[CyRCOR] != info->rco) 1053 if (base_addr[CyRCOR] != info->rco)
1048 base_addr[CyRCOR] = info->rco; 1054 base_addr[CyRCOR] = info->rco;
1049 if (base_addr[CyRBPR] != info->rbpr) 1055 if (base_addr[CyRBPR] != info->rbpr)
1050 base_addr[CyRBPR] = info->rbpr; 1056 base_addr[CyRBPR] = info->rbpr;
1051 1057
1052 /* set line characteristics according configuration */ 1058 /* set line characteristics according configuration */
1053 1059
1054 if (base_addr[CySCHR1] != START_CHAR(info->tty)) 1060 if (base_addr[CySCHR1] != START_CHAR(info->tty))
1055 base_addr[CySCHR1] = START_CHAR(info->tty); 1061 base_addr[CySCHR1] = START_CHAR(info->tty);
1056 if (base_addr[CySCHR2] != STOP_CHAR(info->tty)) 1062 if (base_addr[CySCHR2] != STOP_CHAR(info->tty))
1057 base_addr[CySCHR2] = STOP_CHAR(info->tty); 1063 base_addr[CySCHR2] = STOP_CHAR(info->tty);
1058 if (base_addr[CySCRL] != START_CHAR(info->tty)) 1064 if (base_addr[CySCRL] != START_CHAR(info->tty))
1059 base_addr[CySCRL] = START_CHAR(info->tty); 1065 base_addr[CySCRL] = START_CHAR(info->tty);
1060 if (base_addr[CySCRH] != START_CHAR(info->tty)) 1066 if (base_addr[CySCRH] != START_CHAR(info->tty))
1061 base_addr[CySCRH] = START_CHAR(info->tty); 1067 base_addr[CySCRH] = START_CHAR(info->tty);
1062 if (base_addr[CyCOR1] != info->cor1) 1068 if (base_addr[CyCOR1] != info->cor1)
1063 base_addr[CyCOR1] = info->cor1; 1069 base_addr[CyCOR1] = info->cor1;
1064 if (base_addr[CyCOR2] != info->cor2) 1070 if (base_addr[CyCOR2] != info->cor2)
1065 base_addr[CyCOR2] = info->cor2; 1071 base_addr[CyCOR2] = info->cor2;
1066 if (base_addr[CyCOR3] != info->cor3) 1072 if (base_addr[CyCOR3] != info->cor3)
1067 base_addr[CyCOR3] = info->cor3; 1073 base_addr[CyCOR3] = info->cor3;
1068 if (base_addr[CyCOR4] != info->cor4) 1074 if (base_addr[CyCOR4] != info->cor4)
1069 base_addr[CyCOR4] = info->cor4; 1075 base_addr[CyCOR4] = info->cor4;
1070 if (base_addr[CyCOR5] != info->cor5) 1076 if (base_addr[CyCOR5] != info->cor5)
1071 base_addr[CyCOR5] = info->cor5; 1077 base_addr[CyCOR5] = info->cor5;
1072 if (base_addr[CyCOR6] != info->cor6) 1078 if (base_addr[CyCOR6] != info->cor6)
1073 base_addr[CyCOR6] = info->cor6; 1079 base_addr[CyCOR6] = info->cor6;
1074 if (base_addr[CyCOR7] != info->cor7) 1080 if (base_addr[CyCOR7] != info->cor7)
1075 base_addr[CyCOR7] = info->cor7; 1081 base_addr[CyCOR7] = info->cor7;
1076 1082
1077 if (need_init_chan) 1083 if (need_init_chan)
1078 write_cy_cmd(base_addr,CyINIT_CHAN); 1084 write_cy_cmd(base_addr, CyINIT_CHAN);
1079 1085
1080 base_addr[CyCAR] = (u_char)channel; /* !!! Is this needed? */ 1086 base_addr[CyCAR] = (u_char) channel; /* !!! Is this needed? */
1081 1087
1082 /* 2ms default rx timeout */ 1088 /* 2ms default rx timeout */
1083 ti = info->default_timeout ? info->default_timeout : 0x02; 1089 ti = info->default_timeout ? info->default_timeout : 0x02;
1084 if (base_addr[CyRTPRL] != ti) 1090 if (base_addr[CyRTPRL] != ti)
1085 base_addr[CyRTPRL] = ti; 1091 base_addr[CyRTPRL] = ti;
1086 if (base_addr[CyRTPRH] != 0) 1092 if (base_addr[CyRTPRH] != 0)
1087 base_addr[CyRTPRH] = 0; 1093 base_addr[CyRTPRH] = 0;
1088 1094
1089 /* Set up RTS here also ????? RGH 141095 */ 1095 /* Set up RTS here also ????? RGH 141095 */
1090 if(i == 0){ /* baud rate is zero, turn off line */ 1096 if (i == 0) { /* baud rate is zero, turn off line */
1091 if ((base_addr[CyMSVR2] & CyDTR) == CyDTR) 1097 if ((base_addr[CyMSVR2] & CyDTR) == CyDTR)
1092 base_addr[CyMSVR2] = 0; 1098 base_addr[CyMSVR2] = 0;
1093#ifdef SERIAL_DEBUG_DTR 1099#ifdef SERIAL_DEBUG_DTR
1094 printk("cyc: %d: dropping DTR\n", __LINE__); 1100 printk("cyc: %d: dropping DTR\n", __LINE__);
1095 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]); 1101 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1],
1102 base_addr[CyMSVR2]);
1096#endif 1103#endif
1097 }else{ 1104 } else {
1098 if ((base_addr[CyMSVR2] & CyDTR) != CyDTR) 1105 if ((base_addr[CyMSVR2] & CyDTR) != CyDTR)
1099 base_addr[CyMSVR2] = CyDTR; 1106 base_addr[CyMSVR2] = CyDTR;
1100#ifdef SERIAL_DEBUG_DTR 1107#ifdef SERIAL_DEBUG_DTR
1101 printk("cyc: %d: raising DTR\n", __LINE__); 1108 printk("cyc: %d: raising DTR\n", __LINE__);
1102 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]); 1109 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1],
1110 base_addr[CyMSVR2]);
1103#endif 1111#endif
1104 } 1112 }
1105 1113
1106 if (info->tty){ 1114 if (info->tty) {
1107 clear_bit(TTY_IO_ERROR, &info->tty->flags); 1115 clear_bit(TTY_IO_ERROR, &info->tty->flags);
1108 } 1116 }
1109 1117
1110 local_irq_restore(flags); 1118 local_irq_restore(flags);
1111
1112} /* config_setup */
1113 1119
1120} /* config_setup */
1114 1121
1115static void 1122static void cy_put_char(struct tty_struct *tty, unsigned char ch)
1116cy_put_char(struct tty_struct *tty, unsigned char ch)
1117{ 1123{
1118 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 1124 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1119 unsigned long flags; 1125 unsigned long flags;
1120 1126
1121#ifdef SERIAL_DEBUG_IO 1127#ifdef SERIAL_DEBUG_IO
1122 printk("cy_put_char %s(0x%02x)\n", tty->name, ch); 1128 printk("cy_put_char %s(0x%02x)\n", tty->name, ch);
1123#endif 1129#endif
1124 1130
1125 if (serial_paranoia_check(info, tty->name, "cy_put_char")) 1131 if (serial_paranoia_check(info, tty->name, "cy_put_char"))
1126 return; 1132 return;
1127 1133
1128 if (!info->xmit_buf) 1134 if (!info->xmit_buf)
1129 return; 1135 return;
1130 1136
1131 local_irq_save(flags); 1137 local_irq_save(flags);
1132 if (info->xmit_cnt >= PAGE_SIZE - 1) { 1138 if (info->xmit_cnt >= PAGE_SIZE - 1) {
1133 local_irq_restore(flags); 1139 local_irq_restore(flags);
1134 return; 1140 return;
1135 } 1141 }
1136 1142
1137 info->xmit_buf[info->xmit_head++] = ch; 1143 info->xmit_buf[info->xmit_head++] = ch;
1138 info->xmit_head &= PAGE_SIZE - 1; 1144 info->xmit_head &= PAGE_SIZE - 1;
1139 info->xmit_cnt++; 1145 info->xmit_cnt++;
1140 local_irq_restore(flags); 1146 local_irq_restore(flags);
1141} /* cy_put_char */ 1147} /* cy_put_char */
1142
1143 1148
1144static void 1149static void cy_flush_chars(struct tty_struct *tty)
1145cy_flush_chars(struct tty_struct *tty)
1146{ 1150{
1147 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 1151 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1148 unsigned long flags; 1152 unsigned long flags;
1149 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 1153 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
1150 int channel; 1154 int channel;
1151 1155
1152#ifdef SERIAL_DEBUG_IO 1156#ifdef SERIAL_DEBUG_IO
1153 printk("cy_flush_chars %s\n", tty->name); /* */ 1157 printk("cy_flush_chars %s\n", tty->name); /* */
1154#endif 1158#endif
1155 1159
1156 if (serial_paranoia_check(info, tty->name, "cy_flush_chars")) 1160 if (serial_paranoia_check(info, tty->name, "cy_flush_chars"))
1157 return; 1161 return;
1158 1162
1159 if (info->xmit_cnt <= 0 || tty->stopped 1163 if (info->xmit_cnt <= 0 || tty->stopped
1160 || tty->hw_stopped || !info->xmit_buf) 1164 || tty->hw_stopped || !info->xmit_buf)
1161 return; 1165 return;
1162 1166
1163 channel = info->line; 1167 channel = info->line;
1164 1168
1165 local_irq_save(flags); 1169 local_irq_save(flags);
1166 base_addr[CyCAR] = channel; 1170 base_addr[CyCAR] = channel;
1167 base_addr[CyIER] |= CyTxMpty; 1171 base_addr[CyIER] |= CyTxMpty;
1168 local_irq_restore(flags); 1172 local_irq_restore(flags);
1169} /* cy_flush_chars */ 1173} /* cy_flush_chars */
1170
1171 1174
1172/* This routine gets called when tty_write has put something into 1175/* This routine gets called when tty_write has put something into
1173 the write_queue. If the port is not already transmitting stuff, 1176 the write_queue. If the port is not already transmitting stuff,
@@ -1175,650 +1178,616 @@ cy_flush_chars(struct tty_struct *tty)
1175 routine will then ensure that the characters are sent. If the 1178 routine will then ensure that the characters are sent. If the
1176 port is already active, there is no need to kick it. 1179 port is already active, there is no need to kick it.
1177 */ 1180 */
1178static int 1181static int cy_write(struct tty_struct *tty, const unsigned char *buf, int count)
1179cy_write(struct tty_struct * tty,
1180 const unsigned char *buf, int count)
1181{ 1182{
1182 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 1183 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1183 unsigned long flags; 1184 unsigned long flags;
1184 int c, total = 0; 1185 int c, total = 0;
1185 1186
1186#ifdef SERIAL_DEBUG_IO 1187#ifdef SERIAL_DEBUG_IO
1187 printk("cy_write %s\n", tty->name); /* */ 1188 printk("cy_write %s\n", tty->name); /* */
1188#endif 1189#endif
1189 1190
1190 if (serial_paranoia_check(info, tty->name, "cy_write")){ 1191 if (serial_paranoia_check(info, tty->name, "cy_write")) {
1191 return 0; 1192 return 0;
1192 } 1193 }
1193
1194 if (!info->xmit_buf){
1195 return 0;
1196 }
1197
1198 while (1) {
1199 local_irq_save(flags);
1200 c = min_t(int, count, min(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
1201 SERIAL_XMIT_SIZE - info->xmit_head));
1202 if (c <= 0) {
1203 local_irq_restore(flags);
1204 break;
1205 }
1206
1207 memcpy(info->xmit_buf + info->xmit_head, buf, c);
1208 info->xmit_head = (info->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
1209 info->xmit_cnt += c;
1210 local_irq_restore(flags);
1211
1212 buf += c;
1213 count -= c;
1214 total += c;
1215 }
1216
1217 if (info->xmit_cnt
1218 && !tty->stopped
1219 && !tty->hw_stopped ) {
1220 start_xmit(info);
1221 }
1222 return total;
1223} /* cy_write */
1224 1194
1195 if (!info->xmit_buf) {
1196 return 0;
1197 }
1225 1198
1226static int 1199 while (1) {
1227cy_write_room(struct tty_struct *tty) 1200 local_irq_save(flags);
1201 c = min_t(int, count, min(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
1202 SERIAL_XMIT_SIZE - info->xmit_head));
1203 if (c <= 0) {
1204 local_irq_restore(flags);
1205 break;
1206 }
1207
1208 memcpy(info->xmit_buf + info->xmit_head, buf, c);
1209 info->xmit_head =
1210 (info->xmit_head + c) & (SERIAL_XMIT_SIZE - 1);
1211 info->xmit_cnt += c;
1212 local_irq_restore(flags);
1213
1214 buf += c;
1215 count -= c;
1216 total += c;
1217 }
1218
1219 if (info->xmit_cnt && !tty->stopped && !tty->hw_stopped) {
1220 start_xmit(info);
1221 }
1222 return total;
1223} /* cy_write */
1224
1225static int cy_write_room(struct tty_struct *tty)
1228{ 1226{
1229 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 1227 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1230 int ret; 1228 int ret;
1231 1229
1232#ifdef SERIAL_DEBUG_IO 1230#ifdef SERIAL_DEBUG_IO
1233 printk("cy_write_room %s\n", tty->name); /* */ 1231 printk("cy_write_room %s\n", tty->name); /* */
1234#endif 1232#endif
1235 1233
1236 if (serial_paranoia_check(info, tty->name, "cy_write_room")) 1234 if (serial_paranoia_check(info, tty->name, "cy_write_room"))
1237 return 0; 1235 return 0;
1238 ret = PAGE_SIZE - info->xmit_cnt - 1; 1236 ret = PAGE_SIZE - info->xmit_cnt - 1;
1239 if (ret < 0) 1237 if (ret < 0)
1240 ret = 0; 1238 ret = 0;
1241 return ret; 1239 return ret;
1242} /* cy_write_room */ 1240} /* cy_write_room */
1243
1244 1241
1245static int 1242static int cy_chars_in_buffer(struct tty_struct *tty)
1246cy_chars_in_buffer(struct tty_struct *tty)
1247{ 1243{
1248 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 1244 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1249 1245
1250#ifdef SERIAL_DEBUG_IO 1246#ifdef SERIAL_DEBUG_IO
1251 printk("cy_chars_in_buffer %s %d\n", tty->name, info->xmit_cnt); /* */ 1247 printk("cy_chars_in_buffer %s %d\n", tty->name, info->xmit_cnt); /* */
1252#endif 1248#endif
1253 1249
1254 if (serial_paranoia_check(info, tty->name, "cy_chars_in_buffer")) 1250 if (serial_paranoia_check(info, tty->name, "cy_chars_in_buffer"))
1255 return 0; 1251 return 0;
1256
1257 return info->xmit_cnt;
1258} /* cy_chars_in_buffer */
1259 1252
1253 return info->xmit_cnt;
1254} /* cy_chars_in_buffer */
1260 1255
1261static void 1256static void cy_flush_buffer(struct tty_struct *tty)
1262cy_flush_buffer(struct tty_struct *tty)
1263{ 1257{
1264 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 1258 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1265 unsigned long flags; 1259 unsigned long flags;
1266 1260
1267#ifdef SERIAL_DEBUG_IO 1261#ifdef SERIAL_DEBUG_IO
1268 printk("cy_flush_buffer %s\n", tty->name); /* */ 1262 printk("cy_flush_buffer %s\n", tty->name); /* */
1269#endif 1263#endif
1270 1264
1271 if (serial_paranoia_check(info, tty->name, "cy_flush_buffer")) 1265 if (serial_paranoia_check(info, tty->name, "cy_flush_buffer"))
1272 return; 1266 return;
1273 local_irq_save(flags); 1267 local_irq_save(flags);
1274 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0; 1268 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
1275 local_irq_restore(flags); 1269 local_irq_restore(flags);
1276 tty_wakeup(tty); 1270 tty_wakeup(tty);
1277} /* cy_flush_buffer */ 1271} /* cy_flush_buffer */
1278
1279 1272
1280/* This routine is called by the upper-layer tty layer to signal 1273/* This routine is called by the upper-layer tty layer to signal
1281 that incoming characters should be throttled or that the 1274 that incoming characters should be throttled or that the
1282 throttle should be released. 1275 throttle should be released.
1283 */ 1276 */
1284static void 1277static void cy_throttle(struct tty_struct *tty)
1285cy_throttle(struct tty_struct * tty)
1286{ 1278{
1287 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 1279 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1288 unsigned long flags; 1280 unsigned long flags;
1289 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 1281 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
1290 int channel; 1282 int channel;
1291 1283
1292#ifdef SERIAL_DEBUG_THROTTLE 1284#ifdef SERIAL_DEBUG_THROTTLE
1293 char buf[64]; 1285 char buf[64];
1294 1286
1295 printk("throttle %s: %d....\n", tty_name(tty, buf), 1287 printk("throttle %s: %d....\n", tty_name(tty, buf),
1296 tty->ldisc.chars_in_buffer(tty)); 1288 tty->ldisc.chars_in_buffer(tty));
1297 printk("cy_throttle %s\n", tty->name); 1289 printk("cy_throttle %s\n", tty->name);
1298#endif 1290#endif
1299 1291
1300 if (serial_paranoia_check(info, tty->name, "cy_nthrottle")){ 1292 if (serial_paranoia_check(info, tty->name, "cy_nthrottle")) {
1301 return; 1293 return;
1302 } 1294 }
1303 1295
1304 if (I_IXOFF(tty)) { 1296 if (I_IXOFF(tty)) {
1305 info->x_char = STOP_CHAR(tty); 1297 info->x_char = STOP_CHAR(tty);
1306 /* Should use the "Send Special Character" feature!!! */ 1298 /* Should use the "Send Special Character" feature!!! */
1307 } 1299 }
1308 1300
1309 channel = info->line; 1301 channel = info->line;
1310 1302
1311 local_irq_save(flags); 1303 local_irq_save(flags);
1312 base_addr[CyCAR] = (u_char)channel; 1304 base_addr[CyCAR] = (u_char) channel;
1313 base_addr[CyMSVR1] = 0; 1305 base_addr[CyMSVR1] = 0;
1314 local_irq_restore(flags); 1306 local_irq_restore(flags);
1315 1307} /* cy_throttle */
1316 return;
1317} /* cy_throttle */
1318
1319 1308
1320static void 1309static void cy_unthrottle(struct tty_struct *tty)
1321cy_unthrottle(struct tty_struct * tty)
1322{ 1310{
1323 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 1311 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1324 unsigned long flags; 1312 unsigned long flags;
1325 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 1313 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
1326 int channel; 1314 int channel;
1327 1315
1328#ifdef SERIAL_DEBUG_THROTTLE 1316#ifdef SERIAL_DEBUG_THROTTLE
1329 char buf[64]; 1317 char buf[64];
1330 1318
1331 printk("throttle %s: %d....\n", tty_name(tty, buf), 1319 printk("throttle %s: %d....\n", tty_name(tty, buf),
1332 tty->ldisc.chars_in_buffer(tty)); 1320 tty->ldisc.chars_in_buffer(tty));
1333 printk("cy_unthrottle %s\n", tty->name); 1321 printk("cy_unthrottle %s\n", tty->name);
1334#endif 1322#endif
1335 1323
1336 if (serial_paranoia_check(info, tty->name, "cy_nthrottle")){ 1324 if (serial_paranoia_check(info, tty->name, "cy_nthrottle")) {
1337 return; 1325 return;
1338 } 1326 }
1339 1327
1340 if (I_IXOFF(tty)) { 1328 if (I_IXOFF(tty)) {
1341 info->x_char = START_CHAR(tty); 1329 info->x_char = START_CHAR(tty);
1342 /* Should use the "Send Special Character" feature!!! */ 1330 /* Should use the "Send Special Character" feature!!! */
1343 } 1331 }
1344 1332
1345 channel = info->line; 1333 channel = info->line;
1346 1334
1347 local_irq_save(flags); 1335 local_irq_save(flags);
1348 base_addr[CyCAR] = (u_char)channel; 1336 base_addr[CyCAR] = (u_char) channel;
1349 base_addr[CyMSVR1] = CyRTS; 1337 base_addr[CyMSVR1] = CyRTS;
1350 local_irq_restore(flags); 1338 local_irq_restore(flags);
1351 1339} /* cy_unthrottle */
1352 return;
1353} /* cy_unthrottle */
1354 1340
1355static int 1341static int
1356get_serial_info(struct cyclades_port * info, 1342get_serial_info(struct cyclades_port *info,
1357 struct serial_struct __user * retinfo) 1343 struct serial_struct __user * retinfo)
1358{ 1344{
1359 struct serial_struct tmp; 1345 struct serial_struct tmp;
1360 1346
1361/* CP('g'); */ 1347/* CP('g'); */
1362 if (!retinfo) 1348 if (!retinfo)
1363 return -EFAULT; 1349 return -EFAULT;
1364 memset(&tmp, 0, sizeof(tmp)); 1350 memset(&tmp, 0, sizeof(tmp));
1365 tmp.type = info->type; 1351 tmp.type = info->type;
1366 tmp.line = info->line; 1352 tmp.line = info->line;
1367 tmp.port = info->line; 1353 tmp.port = info->line;
1368 tmp.irq = 0; 1354 tmp.irq = 0;
1369 tmp.flags = info->flags; 1355 tmp.flags = info->flags;
1370 tmp.baud_base = 0; /*!!!*/ 1356 tmp.baud_base = 0; /*!!! */
1371 tmp.close_delay = info->close_delay; 1357 tmp.close_delay = info->close_delay;
1372 tmp.custom_divisor = 0; /*!!!*/ 1358 tmp.custom_divisor = 0; /*!!! */
1373 tmp.hub6 = 0; /*!!!*/ 1359 tmp.hub6 = 0; /*!!! */
1374 return copy_to_user(retinfo,&tmp,sizeof(*retinfo)) ? -EFAULT : 0; 1360 return copy_to_user(retinfo, &tmp, sizeof(*retinfo)) ? -EFAULT : 0;
1375} /* get_serial_info */ 1361} /* get_serial_info */
1376 1362
1377static int 1363static int
1378set_serial_info(struct cyclades_port * info, 1364set_serial_info(struct cyclades_port *info,
1379 struct serial_struct __user * new_info) 1365 struct serial_struct __user * new_info)
1380{ 1366{
1381 struct serial_struct new_serial; 1367 struct serial_struct new_serial;
1382 struct cyclades_port old_info; 1368 struct cyclades_port old_info;
1383 1369
1384/* CP('s'); */ 1370/* CP('s'); */
1385 if (!new_info) 1371 if (!new_info)
1386 return -EFAULT; 1372 return -EFAULT;
1387 if (copy_from_user(&new_serial,new_info,sizeof(new_serial))) 1373 if (copy_from_user(&new_serial, new_info, sizeof(new_serial)))
1388 return -EFAULT; 1374 return -EFAULT;
1389 old_info = *info; 1375 old_info = *info;
1376
1377 if (!capable(CAP_SYS_ADMIN)) {
1378 if ((new_serial.close_delay != info->close_delay) ||
1379 ((new_serial.flags & ASYNC_FLAGS & ~ASYNC_USR_MASK) !=
1380 (info->flags & ASYNC_FLAGS & ~ASYNC_USR_MASK)))
1381 return -EPERM;
1382 info->flags = ((info->flags & ~ASYNC_USR_MASK) |
1383 (new_serial.flags & ASYNC_USR_MASK));
1384 goto check_and_exit;
1385 }
1390 1386
1391 if (!capable(CAP_SYS_ADMIN)) { 1387 /*
1392 if ((new_serial.close_delay != info->close_delay) || 1388 * OK, past this point, all the error checking has been done.
1393 ((new_serial.flags & ASYNC_FLAGS & ~ASYNC_USR_MASK) != 1389 * At this point, we start making changes.....
1394 (info->flags & ASYNC_FLAGS & ~ASYNC_USR_MASK))) 1390 */
1395 return -EPERM;
1396 info->flags = ((info->flags & ~ASYNC_USR_MASK) |
1397 (new_serial.flags & ASYNC_USR_MASK));
1398 goto check_and_exit;
1399 }
1400 1391
1392 info->flags = ((info->flags & ~ASYNC_FLAGS) |
1393 (new_serial.flags & ASYNC_FLAGS));
1394 info->close_delay = new_serial.close_delay;
1401 1395
1402 /* 1396check_and_exit:
1403 * OK, past this point, all the error checking has been done. 1397 if (info->flags & ASYNC_INITIALIZED) {
1404 * At this point, we start making changes..... 1398 config_setup(info);
1405 */ 1399 return 0;
1400 }
1401 return startup(info);
1402} /* set_serial_info */
1406 1403
1407 info->flags = ((info->flags & ~ASYNC_FLAGS) | 1404static int cy_tiocmget(struct tty_struct *tty, struct file *file)
1408 (new_serial.flags & ASYNC_FLAGS)); 1405{
1409 info->close_delay = new_serial.close_delay; 1406 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1407 int channel;
1408 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
1409 unsigned long flags;
1410 unsigned char status;
1410 1411
1412 channel = info->line;
1411 1413
1412check_and_exit: 1414 local_irq_save(flags);
1413 if (info->flags & ASYNC_INITIALIZED){ 1415 base_addr[CyCAR] = (u_char) channel;
1414 config_setup(info); 1416 status = base_addr[CyMSVR1] | base_addr[CyMSVR2];
1415 return 0; 1417 local_irq_restore(flags);
1416 }else{
1417 return startup(info);
1418 }
1419} /* set_serial_info */
1420 1418
1421static int 1419 return ((status & CyRTS) ? TIOCM_RTS : 0)
1422cy_tiocmget(struct tty_struct *tty, struct file *file) 1420 | ((status & CyDTR) ? TIOCM_DTR : 0)
1423{ 1421 | ((status & CyDCD) ? TIOCM_CAR : 0)
1424 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data; 1422 | ((status & CyDSR) ? TIOCM_DSR : 0)
1425 int channel; 1423 | ((status & CyCTS) ? TIOCM_CTS : 0);
1426 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 1424} /* cy_tiocmget */
1427 unsigned long flags;
1428 unsigned char status;
1429
1430 channel = info->line;
1431
1432 local_irq_save(flags);
1433 base_addr[CyCAR] = (u_char)channel;
1434 status = base_addr[CyMSVR1] | base_addr[CyMSVR2];
1435 local_irq_restore(flags);
1436
1437 return ((status & CyRTS) ? TIOCM_RTS : 0)
1438 | ((status & CyDTR) ? TIOCM_DTR : 0)
1439 | ((status & CyDCD) ? TIOCM_CAR : 0)
1440 | ((status & CyDSR) ? TIOCM_DSR : 0)
1441 | ((status & CyCTS) ? TIOCM_CTS : 0);
1442} /* cy_tiocmget */
1443 1425
1444static int 1426static int
1445cy_tiocmset(struct tty_struct *tty, struct file *file, 1427cy_tiocmset(struct tty_struct *tty, struct file *file,
1446 unsigned int set, unsigned int clear) 1428 unsigned int set, unsigned int clear)
1447{ 1429{
1448 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data; 1430 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1449 int channel; 1431 int channel;
1450 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 1432 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
1451 unsigned long flags; 1433 unsigned long flags;
1452 1434
1453 channel = info->line; 1435 channel = info->line;
1454 1436
1455 if (set & TIOCM_RTS){ 1437 if (set & TIOCM_RTS) {
1456 local_irq_save(flags); 1438 local_irq_save(flags);
1457 base_addr[CyCAR] = (u_char)channel; 1439 base_addr[CyCAR] = (u_char) channel;
1458 base_addr[CyMSVR1] = CyRTS; 1440 base_addr[CyMSVR1] = CyRTS;
1459 local_irq_restore(flags); 1441 local_irq_restore(flags);
1460 } 1442 }
1461 if (set & TIOCM_DTR){ 1443 if (set & TIOCM_DTR) {
1462 local_irq_save(flags); 1444 local_irq_save(flags);
1463 base_addr[CyCAR] = (u_char)channel; 1445 base_addr[CyCAR] = (u_char) channel;
1464/* CP('S');CP('2'); */ 1446/* CP('S');CP('2'); */
1465 base_addr[CyMSVR2] = CyDTR; 1447 base_addr[CyMSVR2] = CyDTR;
1466#ifdef SERIAL_DEBUG_DTR 1448#ifdef SERIAL_DEBUG_DTR
1467 printk("cyc: %d: raising DTR\n", __LINE__); 1449 printk("cyc: %d: raising DTR\n", __LINE__);
1468 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]); 1450 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1],
1451 base_addr[CyMSVR2]);
1469#endif 1452#endif
1470 local_irq_restore(flags); 1453 local_irq_restore(flags);
1471 } 1454 }
1472 1455
1473 if (clear & TIOCM_RTS){ 1456 if (clear & TIOCM_RTS) {
1474 local_irq_save(flags); 1457 local_irq_save(flags);
1475 base_addr[CyCAR] = (u_char)channel; 1458 base_addr[CyCAR] = (u_char) channel;
1476 base_addr[CyMSVR1] = 0; 1459 base_addr[CyMSVR1] = 0;
1477 local_irq_restore(flags); 1460 local_irq_restore(flags);
1478 } 1461 }
1479 if (clear & TIOCM_DTR){ 1462 if (clear & TIOCM_DTR) {
1480 local_irq_save(flags); 1463 local_irq_save(flags);
1481 base_addr[CyCAR] = (u_char)channel; 1464 base_addr[CyCAR] = (u_char) channel;
1482/* CP('C');CP('2'); */ 1465/* CP('C');CP('2'); */
1483 base_addr[CyMSVR2] = 0; 1466 base_addr[CyMSVR2] = 0;
1484#ifdef SERIAL_DEBUG_DTR 1467#ifdef SERIAL_DEBUG_DTR
1485 printk("cyc: %d: dropping DTR\n", __LINE__); 1468 printk("cyc: %d: dropping DTR\n", __LINE__);
1486 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]); 1469 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1],
1470 base_addr[CyMSVR2]);
1487#endif 1471#endif
1488 local_irq_restore(flags); 1472 local_irq_restore(flags);
1489 } 1473 }
1490 1474
1491 return 0; 1475 return 0;
1492} /* set_modem_info */ 1476} /* set_modem_info */
1493 1477
1494static void 1478static void send_break(struct cyclades_port *info, int duration)
1495send_break( struct cyclades_port * info, int duration) 1479{ /* Let the transmit ISR take care of this (since it
1496{ /* Let the transmit ISR take care of this (since it 1480 requires stuffing characters into the output stream).
1497 requires stuffing characters into the output stream). 1481 */
1498 */ 1482 info->x_break = duration;
1499 info->x_break = duration; 1483 if (!info->xmit_cnt) {
1500 if (!info->xmit_cnt ) { 1484 start_xmit(info);
1501 start_xmit(info); 1485 }
1502 } 1486} /* send_break */
1503} /* send_break */
1504 1487
1505static int 1488static int
1506get_mon_info(struct cyclades_port * info, struct cyclades_monitor __user * mon) 1489get_mon_info(struct cyclades_port *info, struct cyclades_monitor __user * mon)
1507{ 1490{
1508 1491
1509 if (copy_to_user(mon, &info->mon, sizeof(struct cyclades_monitor))) 1492 if (copy_to_user(mon, &info->mon, sizeof(struct cyclades_monitor)))
1510 return -EFAULT; 1493 return -EFAULT;
1511 info->mon.int_count = 0; 1494 info->mon.int_count = 0;
1512 info->mon.char_count = 0; 1495 info->mon.char_count = 0;
1513 info->mon.char_max = 0; 1496 info->mon.char_max = 0;
1514 info->mon.char_last = 0; 1497 info->mon.char_last = 0;
1515 return 0; 1498 return 0;
1516} 1499}
1517 1500
1518static int 1501static int set_threshold(struct cyclades_port *info, unsigned long __user * arg)
1519set_threshold(struct cyclades_port * info, unsigned long __user *arg)
1520{ 1502{
1521 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 1503 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
1522 unsigned long value; 1504 unsigned long value;
1523 int channel; 1505 int channel;
1524 1506
1525 if (get_user(value, arg)) 1507 if (get_user(value, arg))
1526 return -EFAULT; 1508 return -EFAULT;
1527 1509
1528 channel = info->line; 1510 channel = info->line;
1529 info->cor4 &= ~CyREC_FIFO; 1511 info->cor4 &= ~CyREC_FIFO;
1530 info->cor4 |= value & CyREC_FIFO; 1512 info->cor4 |= value & CyREC_FIFO;
1531 base_addr[CyCOR4] = info->cor4; 1513 base_addr[CyCOR4] = info->cor4;
1532 return 0; 1514 return 0;
1533} 1515}
1534 1516
1535static int 1517static int
1536get_threshold(struct cyclades_port * info, unsigned long __user *value) 1518get_threshold(struct cyclades_port *info, unsigned long __user * value)
1537{ 1519{
1538 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 1520 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
1539 int channel; 1521 int channel;
1540 unsigned long tmp; 1522 unsigned long tmp;
1541 1523
1542 channel = info->line; 1524 channel = info->line;
1543 1525
1544 tmp = base_addr[CyCOR4] & CyREC_FIFO; 1526 tmp = base_addr[CyCOR4] & CyREC_FIFO;
1545 return put_user(tmp,value); 1527 return put_user(tmp, value);
1546} 1528}
1547 1529
1548static int 1530static int
1549set_default_threshold(struct cyclades_port * info, unsigned long __user *arg) 1531set_default_threshold(struct cyclades_port *info, unsigned long __user * arg)
1550{ 1532{
1551 unsigned long value; 1533 unsigned long value;
1552 1534
1553 if (get_user(value, arg)) 1535 if (get_user(value, arg))
1554 return -EFAULT; 1536 return -EFAULT;
1555 1537
1556 info->default_threshold = value & 0x0f; 1538 info->default_threshold = value & 0x0f;
1557 return 0; 1539 return 0;
1558} 1540}
1559 1541
1560static int 1542static int
1561get_default_threshold(struct cyclades_port * info, unsigned long __user *value) 1543get_default_threshold(struct cyclades_port *info, unsigned long __user * value)
1562{ 1544{
1563 return put_user(info->default_threshold,value); 1545 return put_user(info->default_threshold, value);
1564} 1546}
1565 1547
1566static int 1548static int set_timeout(struct cyclades_port *info, unsigned long __user * arg)
1567set_timeout(struct cyclades_port * info, unsigned long __user *arg)
1568{ 1549{
1569 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 1550 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
1570 int channel; 1551 int channel;
1571 unsigned long value; 1552 unsigned long value;
1572 1553
1573 if (get_user(value, arg)) 1554 if (get_user(value, arg))
1574 return -EFAULT; 1555 return -EFAULT;
1575 1556
1576 channel = info->line; 1557 channel = info->line;
1577 1558
1578 base_addr[CyRTPRL] = value & 0xff; 1559 base_addr[CyRTPRL] = value & 0xff;
1579 base_addr[CyRTPRH] = (value >> 8) & 0xff; 1560 base_addr[CyRTPRH] = (value >> 8) & 0xff;
1580 return 0; 1561 return 0;
1581} 1562}
1582 1563
1583static int 1564static int get_timeout(struct cyclades_port *info, unsigned long __user * value)
1584get_timeout(struct cyclades_port * info, unsigned long __user *value)
1585{ 1565{
1586 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 1566 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
1587 int channel; 1567 int channel;
1588 unsigned long tmp; 1568 unsigned long tmp;
1589 1569
1590 channel = info->line; 1570 channel = info->line;
1591 1571
1592 tmp = base_addr[CyRTPRL]; 1572 tmp = base_addr[CyRTPRL];
1593 return put_user(tmp,value); 1573 return put_user(tmp, value);
1594} 1574}
1595 1575
1596static int 1576static int set_default_timeout(struct cyclades_port *info, unsigned long value)
1597set_default_timeout(struct cyclades_port * info, unsigned long value)
1598{ 1577{
1599 info->default_timeout = value & 0xff; 1578 info->default_timeout = value & 0xff;
1600 return 0; 1579 return 0;
1601} 1580}
1602 1581
1603static int 1582static int
1604get_default_timeout(struct cyclades_port * info, unsigned long __user *value) 1583get_default_timeout(struct cyclades_port *info, unsigned long __user * value)
1605{ 1584{
1606 return put_user(info->default_timeout,value); 1585 return put_user(info->default_timeout, value);
1607} 1586}
1608 1587
1609static int 1588static int
1610cy_ioctl(struct tty_struct *tty, struct file * file, 1589cy_ioctl(struct tty_struct *tty, struct file *file,
1611 unsigned int cmd, unsigned long arg) 1590 unsigned int cmd, unsigned long arg)
1612{ 1591{
1613 unsigned long val; 1592 unsigned long val;
1614 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data; 1593 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1615 int ret_val = 0; 1594 int ret_val = 0;
1616 void __user *argp = (void __user *)arg; 1595 void __user *argp = (void __user *)arg;
1617 1596
1618#ifdef SERIAL_DEBUG_OTHER 1597#ifdef SERIAL_DEBUG_OTHER
1619 printk("cy_ioctl %s, cmd = %x arg = %lx\n", tty->name, cmd, arg); /* */ 1598 printk("cy_ioctl %s, cmd = %x arg = %lx\n", tty->name, cmd, arg); /* */
1620#endif 1599#endif
1621 1600
1622 switch (cmd) { 1601 switch (cmd) {
1623 case CYGETMON: 1602 case CYGETMON:
1624 ret_val = get_mon_info(info, argp); 1603 ret_val = get_mon_info(info, argp);
1625 break; 1604 break;
1626 case CYGETTHRESH: 1605 case CYGETTHRESH:
1627 ret_val = get_threshold(info, argp); 1606 ret_val = get_threshold(info, argp);
1628 break; 1607 break;
1629 case CYSETTHRESH: 1608 case CYSETTHRESH:
1630 ret_val = set_threshold(info, argp); 1609 ret_val = set_threshold(info, argp);
1631 break; 1610 break;
1632 case CYGETDEFTHRESH: 1611 case CYGETDEFTHRESH:
1633 ret_val = get_default_threshold(info, argp); 1612 ret_val = get_default_threshold(info, argp);
1634 break; 1613 break;
1635 case CYSETDEFTHRESH: 1614 case CYSETDEFTHRESH:
1636 ret_val = set_default_threshold(info, argp); 1615 ret_val = set_default_threshold(info, argp);
1637 break; 1616 break;
1638 case CYGETTIMEOUT: 1617 case CYGETTIMEOUT:
1639 ret_val = get_timeout(info, argp); 1618 ret_val = get_timeout(info, argp);
1640 break; 1619 break;
1641 case CYSETTIMEOUT: 1620 case CYSETTIMEOUT:
1642 ret_val = set_timeout(info, argp); 1621 ret_val = set_timeout(info, argp);
1643 break; 1622 break;
1644 case CYGETDEFTIMEOUT: 1623 case CYGETDEFTIMEOUT:
1645 ret_val = get_default_timeout(info, argp); 1624 ret_val = get_default_timeout(info, argp);
1646 break; 1625 break;
1647 case CYSETDEFTIMEOUT: 1626 case CYSETDEFTIMEOUT:
1648 ret_val = set_default_timeout(info, (unsigned long)arg); 1627 ret_val = set_default_timeout(info, (unsigned long)arg);
1649 break; 1628 break;
1650 case TCSBRK: /* SVID version: non-zero arg --> no break */ 1629 case TCSBRK: /* SVID version: non-zero arg --> no break */
1651 ret_val = tty_check_change(tty); 1630 ret_val = tty_check_change(tty);
1652 if (ret_val) 1631 if (ret_val)
1653 break; 1632 break;
1654 tty_wait_until_sent(tty,0); 1633 tty_wait_until_sent(tty, 0);
1655 if (!arg) 1634 if (!arg)
1656 send_break(info, HZ/4); /* 1/4 second */ 1635 send_break(info, HZ / 4); /* 1/4 second */
1657 break; 1636 break;
1658 case TCSBRKP: /* support for POSIX tcsendbreak() */ 1637 case TCSBRKP: /* support for POSIX tcsendbreak() */
1659 ret_val = tty_check_change(tty); 1638 ret_val = tty_check_change(tty);
1660 if (ret_val) 1639 if (ret_val)
1640 break;
1641 tty_wait_until_sent(tty, 0);
1642 send_break(info, arg ? arg * (HZ / 10) : HZ / 4);
1661 break; 1643 break;
1662 tty_wait_until_sent(tty,0);
1663 send_break(info, arg ? arg*(HZ/10) : HZ/4);
1664 break;
1665 1644
1666/* The following commands are incompletely implemented!!! */ 1645/* The following commands are incompletely implemented!!! */
1667 case TIOCGSOFTCAR: 1646 case TIOCGSOFTCAR:
1668 ret_val = put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long __user *) argp); 1647 ret_val =
1669 break; 1648 put_user(C_CLOCAL(tty) ? 1 : 0,
1670 case TIOCSSOFTCAR: 1649 (unsigned long __user *)argp);
1671 ret_val = get_user(val, (unsigned long __user *) argp); 1650 break;
1672 if (ret_val) 1651 case TIOCSSOFTCAR:
1673 break; 1652 ret_val = get_user(val, (unsigned long __user *)argp);
1674 tty->termios->c_cflag = 1653 if (ret_val)
1675 ((tty->termios->c_cflag & ~CLOCAL) | (val ? CLOCAL : 0)); 1654 break;
1676 break; 1655 tty->termios->c_cflag =
1677 case TIOCGSERIAL: 1656 ((tty->termios->c_cflag & ~CLOCAL) | (val ? CLOCAL : 0));
1678 ret_val = get_serial_info(info, argp); 1657 break;
1679 break; 1658 case TIOCGSERIAL:
1680 case TIOCSSERIAL: 1659 ret_val = get_serial_info(info, argp);
1681 ret_val = set_serial_info(info, argp); 1660 break;
1682 break; 1661 case TIOCSSERIAL:
1683 default: 1662 ret_val = set_serial_info(info, argp);
1684 ret_val = -ENOIOCTLCMD; 1663 break;
1685 } 1664 default:
1665 ret_val = -ENOIOCTLCMD;
1666 }
1686 1667
1687#ifdef SERIAL_DEBUG_OTHER 1668#ifdef SERIAL_DEBUG_OTHER
1688 printk("cy_ioctl done\n"); 1669 printk("cy_ioctl done\n");
1689#endif 1670#endif
1690 1671
1691 return ret_val; 1672 return ret_val;
1692} /* cy_ioctl */ 1673} /* cy_ioctl */
1693
1694 1674
1695 1675static void cy_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1696
1697static void
1698cy_set_termios(struct tty_struct *tty, struct ktermios * old_termios)
1699{ 1676{
1700 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 1677 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1701 1678
1702#ifdef SERIAL_DEBUG_OTHER 1679#ifdef SERIAL_DEBUG_OTHER
1703 printk("cy_set_termios %s\n", tty->name); 1680 printk("cy_set_termios %s\n", tty->name);
1704#endif 1681#endif
1705 1682
1706 if (tty->termios->c_cflag == old_termios->c_cflag) 1683 if (tty->termios->c_cflag == old_termios->c_cflag)
1707 return; 1684 return;
1708 config_setup(info); 1685 config_setup(info);
1709 1686
1710 if ((old_termios->c_cflag & CRTSCTS) && 1687 if ((old_termios->c_cflag & CRTSCTS) &&
1711 !(tty->termios->c_cflag & CRTSCTS)) { 1688 !(tty->termios->c_cflag & CRTSCTS)) {
1712 tty->stopped = 0; 1689 tty->stopped = 0;
1713 cy_start(tty); 1690 cy_start(tty);
1714 } 1691 }
1715#ifdef tytso_patch_94Nov25_1726 1692#ifdef tytso_patch_94Nov25_1726
1716 if (!(old_termios->c_cflag & CLOCAL) && 1693 if (!(old_termios->c_cflag & CLOCAL) &&
1717 (tty->termios->c_cflag & CLOCAL)) 1694 (tty->termios->c_cflag & CLOCAL))
1718 wake_up_interruptible(&info->open_wait); 1695 wake_up_interruptible(&info->open_wait);
1719#endif 1696#endif
1697} /* cy_set_termios */
1720 1698
1721 return; 1699static void cy_close(struct tty_struct *tty, struct file *filp)
1722} /* cy_set_termios */
1723
1724
1725static void
1726cy_close(struct tty_struct * tty, struct file * filp)
1727{ 1700{
1728 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data; 1701 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1729 1702
1730/* CP('C'); */ 1703/* CP('C'); */
1731#ifdef SERIAL_DEBUG_OTHER 1704#ifdef SERIAL_DEBUG_OTHER
1732 printk("cy_close %s\n", tty->name); 1705 printk("cy_close %s\n", tty->name);
1733#endif 1706#endif
1734 1707
1735 if (!info 1708 if (!info || serial_paranoia_check(info, tty->name, "cy_close")) {
1736 || serial_paranoia_check(info, tty->name, "cy_close")){ 1709 return;
1737 return; 1710 }
1738 }
1739#ifdef SERIAL_DEBUG_OPEN 1711#ifdef SERIAL_DEBUG_OPEN
1740 printk("cy_close %s, count = %d\n", tty->name, info->count); 1712 printk("cy_close %s, count = %d\n", tty->name, info->count);
1741#endif 1713#endif
1742 1714
1743 if ((tty->count == 1) && (info->count != 1)) { 1715 if ((tty->count == 1) && (info->count != 1)) {
1744 /* 1716 /*
1745 * Uh, oh. tty->count is 1, which means that the tty 1717 * Uh, oh. tty->count is 1, which means that the tty
1746 * structure will be freed. Info->count should always 1718 * structure will be freed. Info->count should always
1747 * be one in these conditions. If it's greater than 1719 * be one in these conditions. If it's greater than
1748 * one, we've got real problems, since it means the 1720 * one, we've got real problems, since it means the
1749 * serial port won't be shutdown. 1721 * serial port won't be shutdown.
1750 */ 1722 */
1751 printk("cy_close: bad serial port count; tty->count is 1, " 1723 printk("cy_close: bad serial port count; tty->count is 1, "
1752 "info->count is %d\n", info->count); 1724 "info->count is %d\n", info->count);
1753 info->count = 1; 1725 info->count = 1;
1754 } 1726 }
1755#ifdef SERIAL_DEBUG_COUNT 1727#ifdef SERIAL_DEBUG_COUNT
1756 printk("cyc: %d: decrementing count to %d\n", __LINE__, info->count - 1); 1728 printk("cyc: %d: decrementing count to %d\n", __LINE__,
1729 info->count - 1);
1757#endif 1730#endif
1758 if (--info->count < 0) { 1731 if (--info->count < 0) {
1759 printk("cy_close: bad serial port count for ttys%d: %d\n", 1732 printk("cy_close: bad serial port count for ttys%d: %d\n",
1760 info->line, info->count); 1733 info->line, info->count);
1761#ifdef SERIAL_DEBUG_COUNT 1734#ifdef SERIAL_DEBUG_COUNT
1762 printk("cyc: %d: setting count to 0\n", __LINE__); 1735 printk("cyc: %d: setting count to 0\n", __LINE__);
1763#endif 1736#endif
1764 info->count = 0; 1737 info->count = 0;
1765 }
1766 if (info->count)
1767 return;
1768 info->flags |= ASYNC_CLOSING;
1769 if (info->flags & ASYNC_INITIALIZED)
1770 tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */
1771 shutdown(info);
1772 if (tty->driver->flush_buffer)
1773 tty->driver->flush_buffer(tty);
1774 tty_ldisc_flush(tty);
1775 info->event = 0;
1776 info->tty = NULL;
1777 if (info->blocked_open) {
1778 if (info->close_delay) {
1779 msleep_interruptible(jiffies_to_msecs(info->close_delay));
1780 } 1738 }
1781 wake_up_interruptible(&info->open_wait); 1739 if (info->count)
1782 } 1740 return;
1783 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING); 1741 info->flags |= ASYNC_CLOSING;
1784 wake_up_interruptible(&info->close_wait); 1742 if (info->flags & ASYNC_INITIALIZED)
1743 tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */
1744 shutdown(info);
1745 if (tty->driver->flush_buffer)
1746 tty->driver->flush_buffer(tty);
1747 tty_ldisc_flush(tty);
1748 info->event = 0;
1749 info->tty = NULL;
1750 if (info->blocked_open) {
1751 if (info->close_delay) {
1752 msleep_interruptible(jiffies_to_msecs
1753 (info->close_delay));
1754 }
1755 wake_up_interruptible(&info->open_wait);
1756 }
1757 info->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING);
1758 wake_up_interruptible(&info->close_wait);
1785 1759
1786#ifdef SERIAL_DEBUG_OTHER 1760#ifdef SERIAL_DEBUG_OTHER
1787 printk("cy_close done\n"); 1761 printk("cy_close done\n");
1788#endif 1762#endif
1789 1763} /* cy_close */
1790 return;
1791} /* cy_close */
1792 1764
1793/* 1765/*
1794 * cy_hangup() --- called by tty_hangup() when a hangup is signaled. 1766 * cy_hangup() --- called by tty_hangup() when a hangup is signaled.
1795 */ 1767 */
1796void 1768void cy_hangup(struct tty_struct *tty)
1797cy_hangup(struct tty_struct *tty)
1798{ 1769{
1799 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data; 1770 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1800 1771
1801#ifdef SERIAL_DEBUG_OTHER 1772#ifdef SERIAL_DEBUG_OTHER
1802 printk("cy_hangup %s\n", tty->name); /* */ 1773 printk("cy_hangup %s\n", tty->name); /* */
1803#endif 1774#endif
1804 1775
1805 if (serial_paranoia_check(info, tty->name, "cy_hangup")) 1776 if (serial_paranoia_check(info, tty->name, "cy_hangup"))
1806 return; 1777 return;
1807 1778
1808 shutdown(info); 1779 shutdown(info);
1809#if 0 1780#if 0
1810 info->event = 0; 1781 info->event = 0;
1811 info->count = 0; 1782 info->count = 0;
1812#ifdef SERIAL_DEBUG_COUNT 1783#ifdef SERIAL_DEBUG_COUNT
1813 printk("cyc: %d: setting count to 0\n", __LINE__); 1784 printk("cyc: %d: setting count to 0\n", __LINE__);
1814#endif 1785#endif
1815 info->tty = 0; 1786 info->tty = 0;
1816#endif 1787#endif
1817 info->flags &= ~ASYNC_NORMAL_ACTIVE; 1788 info->flags &= ~ASYNC_NORMAL_ACTIVE;
1818 wake_up_interruptible(&info->open_wait); 1789 wake_up_interruptible(&info->open_wait);
1819} /* cy_hangup */ 1790} /* cy_hangup */
1820
1821
1822 1791
1823/* 1792/*
1824 * ------------------------------------------------------------ 1793 * ------------------------------------------------------------
@@ -1827,177 +1796,180 @@ cy_hangup(struct tty_struct *tty)
1827 */ 1796 */
1828 1797
1829static int 1798static int
1830block_til_ready(struct tty_struct *tty, struct file * filp, 1799block_til_ready(struct tty_struct *tty, struct file *filp,
1831 struct cyclades_port *info) 1800 struct cyclades_port *info)
1832{ 1801{
1833 DECLARE_WAITQUEUE(wait, current); 1802 DECLARE_WAITQUEUE(wait, current);
1834 unsigned long flags; 1803 unsigned long flags;
1835 int channel; 1804 int channel;
1836 int retval; 1805 int retval;
1837 volatile u_char *base_addr = (u_char *)BASE_ADDR; 1806 volatile u_char *base_addr = (u_char *) BASE_ADDR;
1838 1807
1839 /* 1808 /*
1840 * If the device is in the middle of being closed, then block 1809 * If the device is in the middle of being closed, then block
1841 * until it's done, and then try again. 1810 * until it's done, and then try again.
1842 */ 1811 */
1843 if (info->flags & ASYNC_CLOSING) { 1812 if (info->flags & ASYNC_CLOSING) {
1844 interruptible_sleep_on(&info->close_wait); 1813 interruptible_sleep_on(&info->close_wait);
1845 if (info->flags & ASYNC_HUP_NOTIFY){ 1814 if (info->flags & ASYNC_HUP_NOTIFY) {
1846 return -EAGAIN; 1815 return -EAGAIN;
1847 }else{ 1816 } else {
1848 return -ERESTARTSYS; 1817 return -ERESTARTSYS;
1849 } 1818 }
1850 } 1819 }
1851 1820
1852 /* 1821 /*
1853 * If non-blocking mode is set, then make the check up front 1822 * If non-blocking mode is set, then make the check up front
1854 * and then exit. 1823 * and then exit.
1855 */ 1824 */
1856 if (filp->f_flags & O_NONBLOCK) { 1825 if (filp->f_flags & O_NONBLOCK) {
1857 info->flags |= ASYNC_NORMAL_ACTIVE; 1826 info->flags |= ASYNC_NORMAL_ACTIVE;
1858 return 0; 1827 return 0;
1859 } 1828 }
1860 1829
1861 /* 1830 /*
1862 * Block waiting for the carrier detect and the line to become 1831 * Block waiting for the carrier detect and the line to become
1863 * free (i.e., not in use by the callout). While we are in 1832 * free (i.e., not in use by the callout). While we are in
1864 * this loop, info->count is dropped by one, so that 1833 * this loop, info->count is dropped by one, so that
1865 * cy_close() knows when to free things. We restore it upon 1834 * cy_close() knows when to free things. We restore it upon
1866 * exit, either normal or abnormal. 1835 * exit, either normal or abnormal.
1867 */ 1836 */
1868 retval = 0; 1837 retval = 0;
1869 add_wait_queue(&info->open_wait, &wait); 1838 add_wait_queue(&info->open_wait, &wait);
1870#ifdef SERIAL_DEBUG_OPEN 1839#ifdef SERIAL_DEBUG_OPEN
1871 printk("block_til_ready before block: %s, count = %d\n", 1840 printk("block_til_ready before block: %s, count = %d\n",
1872 tty->name, info->count);/**/ 1841 tty->name, info->count);
1842 /**/
1873#endif 1843#endif
1874 info->count--; 1844 info->count--;
1875#ifdef SERIAL_DEBUG_COUNT 1845#ifdef SERIAL_DEBUG_COUNT
1876 printk("cyc: %d: decrementing count to %d\n", __LINE__, info->count); 1846 printk("cyc: %d: decrementing count to %d\n", __LINE__, info->count);
1877#endif 1847#endif
1878 info->blocked_open++; 1848 info->blocked_open++;
1879 1849
1880 channel = info->line; 1850 channel = info->line;
1881 1851
1882 while (1) { 1852 while (1) {
1883 local_irq_save(flags); 1853 local_irq_save(flags);
1884 base_addr[CyCAR] = (u_char)channel; 1854 base_addr[CyCAR] = (u_char) channel;
1885 base_addr[CyMSVR1] = CyRTS; 1855 base_addr[CyMSVR1] = CyRTS;
1886/* CP('S');CP('4'); */ 1856/* CP('S');CP('4'); */
1887 base_addr[CyMSVR2] = CyDTR; 1857 base_addr[CyMSVR2] = CyDTR;
1888#ifdef SERIAL_DEBUG_DTR 1858#ifdef SERIAL_DEBUG_DTR
1889 printk("cyc: %d: raising DTR\n", __LINE__); 1859 printk("cyc: %d: raising DTR\n", __LINE__);
1890 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]); 1860 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1],
1891#endif 1861 base_addr[CyMSVR2]);
1892 local_irq_restore(flags); 1862#endif
1893 set_current_state(TASK_INTERRUPTIBLE); 1863 local_irq_restore(flags);
1894 if (tty_hung_up_p(filp) 1864 set_current_state(TASK_INTERRUPTIBLE);
1895 || !(info->flags & ASYNC_INITIALIZED) ){ 1865 if (tty_hung_up_p(filp)
1896 if (info->flags & ASYNC_HUP_NOTIFY) { 1866 || !(info->flags & ASYNC_INITIALIZED)) {
1897 retval = -EAGAIN; 1867 if (info->flags & ASYNC_HUP_NOTIFY) {
1898 }else{ 1868 retval = -EAGAIN;
1899 retval = -ERESTARTSYS; 1869 } else {
1900 } 1870 retval = -ERESTARTSYS;
1901 break; 1871 }
1902 } 1872 break;
1903 local_irq_save(flags); 1873 }
1904 base_addr[CyCAR] = (u_char)channel; 1874 local_irq_save(flags);
1875 base_addr[CyCAR] = (u_char) channel;
1905/* CP('L');CP1(1 && C_CLOCAL(tty)); CP1(1 && (base_addr[CyMSVR1] & CyDCD) ); */ 1876/* CP('L');CP1(1 && C_CLOCAL(tty)); CP1(1 && (base_addr[CyMSVR1] & CyDCD) ); */
1906 if (!(info->flags & ASYNC_CLOSING) 1877 if (!(info->flags & ASYNC_CLOSING)
1907 && (C_CLOCAL(tty) 1878 && (C_CLOCAL(tty)
1908 || (base_addr[CyMSVR1] & CyDCD))) { 1879 || (base_addr[CyMSVR1] & CyDCD))) {
1909 local_irq_restore(flags); 1880 local_irq_restore(flags);
1910 break; 1881 break;
1911 } 1882 }
1912 local_irq_restore(flags); 1883 local_irq_restore(flags);
1913 if (signal_pending(current)) { 1884 if (signal_pending(current)) {
1914 retval = -ERESTARTSYS; 1885 retval = -ERESTARTSYS;
1915 break; 1886 break;
1916 } 1887 }
1917#ifdef SERIAL_DEBUG_OPEN 1888#ifdef SERIAL_DEBUG_OPEN
1918 printk("block_til_ready blocking: %s, count = %d\n", 1889 printk("block_til_ready blocking: %s, count = %d\n",
1919 tty->name, info->count);/**/ 1890 tty->name, info->count);
1920#endif 1891 /**/
1921 schedule(); 1892#endif
1922 } 1893 schedule();
1923 current->state = TASK_RUNNING; 1894 }
1924 remove_wait_queue(&info->open_wait, &wait); 1895 current->state = TASK_RUNNING;
1925 if (!tty_hung_up_p(filp)){ 1896 remove_wait_queue(&info->open_wait, &wait);
1926 info->count++; 1897 if (!tty_hung_up_p(filp)) {
1898 info->count++;
1927#ifdef SERIAL_DEBUG_COUNT 1899#ifdef SERIAL_DEBUG_COUNT
1928 printk("cyc: %d: incrementing count to %d\n", __LINE__, info->count); 1900 printk("cyc: %d: incrementing count to %d\n", __LINE__,
1901 info->count);
1929#endif 1902#endif
1930 } 1903 }
1931 info->blocked_open--; 1904 info->blocked_open--;
1932#ifdef SERIAL_DEBUG_OPEN 1905#ifdef SERIAL_DEBUG_OPEN
1933 printk("block_til_ready after blocking: %s, count = %d\n", 1906 printk("block_til_ready after blocking: %s, count = %d\n",
1934 tty->name, info->count);/**/ 1907 tty->name, info->count);
1908 /**/
1935#endif 1909#endif
1936 if (retval) 1910 if (retval)
1937 return retval; 1911 return retval;
1938 info->flags |= ASYNC_NORMAL_ACTIVE; 1912 info->flags |= ASYNC_NORMAL_ACTIVE;
1939 return 0; 1913 return 0;
1940} /* block_til_ready */ 1914} /* block_til_ready */
1941 1915
1942/* 1916/*
1943 * This routine is called whenever a serial port is opened. It 1917 * This routine is called whenever a serial port is opened. It
1944 * performs the serial-specific initialization for the tty structure. 1918 * performs the serial-specific initialization for the tty structure.
1945 */ 1919 */
1946int 1920int cy_open(struct tty_struct *tty, struct file *filp)
1947cy_open(struct tty_struct *tty, struct file * filp)
1948{ 1921{
1949 struct cyclades_port *info; 1922 struct cyclades_port *info;
1950 int retval, line; 1923 int retval, line;
1951 1924
1952/* CP('O'); */ 1925/* CP('O'); */
1953 line = tty->index; 1926 line = tty->index;
1954 if ((line < 0) || (NR_PORTS <= line)){ 1927 if ((line < 0) || (NR_PORTS <= line)) {
1955 return -ENODEV; 1928 return -ENODEV;
1956 } 1929 }
1957 info = &cy_port[line]; 1930 info = &cy_port[line];
1958 if (info->line < 0){ 1931 if (info->line < 0) {
1959 return -ENODEV; 1932 return -ENODEV;
1960 } 1933 }
1961#ifdef SERIAL_DEBUG_OTHER 1934#ifdef SERIAL_DEBUG_OTHER
1962 printk("cy_open %s\n", tty->name); /* */ 1935 printk("cy_open %s\n", tty->name); /* */
1963#endif 1936#endif
1964 if (serial_paranoia_check(info, tty->name, "cy_open")){ 1937 if (serial_paranoia_check(info, tty->name, "cy_open")) {
1965 return -ENODEV; 1938 return -ENODEV;
1966 } 1939 }
1967#ifdef SERIAL_DEBUG_OPEN 1940#ifdef SERIAL_DEBUG_OPEN
1968 printk("cy_open %s, count = %d\n", tty->name, info->count);/**/ 1941 printk("cy_open %s, count = %d\n", tty->name, info->count);
1942 /**/
1969#endif 1943#endif
1970 info->count++; 1944 info->count++;
1971#ifdef SERIAL_DEBUG_COUNT 1945#ifdef SERIAL_DEBUG_COUNT
1972 printk("cyc: %d: incrementing count to %d\n", __LINE__, info->count); 1946 printk("cyc: %d: incrementing count to %d\n", __LINE__, info->count);
1973#endif 1947#endif
1974 tty->driver_data = info; 1948 tty->driver_data = info;
1975 info->tty = tty; 1949 info->tty = tty;
1976 1950
1977 /* 1951 /*
1978 * Start up serial port 1952 * Start up serial port
1979 */ 1953 */
1980 retval = startup(info); 1954 retval = startup(info);
1981 if (retval){ 1955 if (retval) {
1982 return retval; 1956 return retval;
1983 } 1957 }
1984 1958
1985 retval = block_til_ready(tty, filp, info); 1959 retval = block_til_ready(tty, filp, info);
1986 if (retval) { 1960 if (retval) {
1987#ifdef SERIAL_DEBUG_OPEN 1961#ifdef SERIAL_DEBUG_OPEN
1988 printk("cy_open returning after block_til_ready with %d\n", 1962 printk("cy_open returning after block_til_ready with %d\n",
1989 retval); 1963 retval);
1990#endif 1964#endif
1991 return retval; 1965 return retval;
1992 } 1966 }
1993
1994#ifdef SERIAL_DEBUG_OPEN 1967#ifdef SERIAL_DEBUG_OPEN
1995 printk("cy_open done\n");/**/ 1968 printk("cy_open done\n");
1969 /**/
1996#endif 1970#endif
1997 return 0; 1971 return 0;
1998} /* cy_open */ 1972} /* cy_open */
1999
2000
2001 1973
2002/* 1974/*
2003 * --------------------------------------------------------------------- 1975 * ---------------------------------------------------------------------
@@ -2012,11 +1984,10 @@ cy_open(struct tty_struct *tty, struct file * filp)
2012 * number, and identifies which options were configured into this 1984 * number, and identifies which options were configured into this
2013 * driver. 1985 * driver.
2014 */ 1986 */
2015static void 1987static void show_version(void)
2016show_version(void)
2017{ 1988{
2018 printk("MVME166/167 cd2401 driver\n"); 1989 printk("MVME166/167 cd2401 driver\n");
2019} /* show_version */ 1990} /* show_version */
2020 1991
2021/* initialize chips on card -- return number of valid 1992/* initialize chips on card -- return number of valid
2022 chips (which is number of ports/4) */ 1993 chips (which is number of ports/4) */
@@ -2030,10 +2001,9 @@ show_version(void)
2030 * ... I wonder what I should do if this fails ... 2001 * ... I wonder what I should do if this fails ...
2031 */ 2002 */
2032 2003
2033void 2004void mvme167_serial_console_setup(int cflag)
2034mvme167_serial_console_setup(int cflag)
2035{ 2005{
2036 volatile unsigned char* base_addr = (u_char *)BASE_ADDR; 2006 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
2037 int ch; 2007 int ch;
2038 u_char spd; 2008 u_char spd;
2039 u_char rcor, rbpr, badspeed = 0; 2009 u_char rcor, rbpr, badspeed = 0;
@@ -2062,21 +2032,21 @@ mvme167_serial_console_setup(int cflag)
2062 2032
2063 /* OK, we have chosen a speed, now reset and reinitialise */ 2033 /* OK, we have chosen a speed, now reset and reinitialise */
2064 2034
2065 my_udelay(20000L); /* Allow time for any active o/p to complete */ 2035 my_udelay(20000L); /* Allow time for any active o/p to complete */
2066 if(base_addr[CyCCR] != 0x00){ 2036 if (base_addr[CyCCR] != 0x00) {
2067 local_irq_restore(flags); 2037 local_irq_restore(flags);
2068 /* printk(" chip is never idle (CCR != 0)\n"); */ 2038 /* printk(" chip is never idle (CCR != 0)\n"); */
2069 return; 2039 return;
2070 } 2040 }
2071 2041
2072 base_addr[CyCCR] = CyCHIP_RESET; /* Reset the chip */ 2042 base_addr[CyCCR] = CyCHIP_RESET; /* Reset the chip */
2073 my_udelay(1000L); 2043 my_udelay(1000L);
2074 2044
2075 if(base_addr[CyGFRCR] == 0x00){ 2045 if (base_addr[CyGFRCR] == 0x00) {
2076 local_irq_restore(flags); 2046 local_irq_restore(flags);
2077 /* printk(" chip is not responding (GFRCR stayed 0)\n"); */ 2047 /* printk(" chip is not responding (GFRCR stayed 0)\n"); */
2078 return; 2048 return;
2079 } 2049 }
2080 2050
2081 /* 2051 /*
2082 * System clock is 20Mhz, divided by 2048, so divide by 10 for a 1.0ms 2052 * System clock is 20Mhz, divided by 2048, so divide by 10 for a 1.0ms
@@ -2085,9 +2055,9 @@ mvme167_serial_console_setup(int cflag)
2085 2055
2086 base_addr[CyTPR] = 10; 2056 base_addr[CyTPR] = 10;
2087 2057
2088 base_addr[CyPILR1] = 0x01; /* Interrupt level for modem change */ 2058 base_addr[CyPILR1] = 0x01; /* Interrupt level for modem change */
2089 base_addr[CyPILR2] = 0x02; /* Interrupt level for tx ints */ 2059 base_addr[CyPILR2] = 0x02; /* Interrupt level for tx ints */
2090 base_addr[CyPILR3] = 0x03; /* Interrupt level for rx ints */ 2060 base_addr[CyPILR3] = 0x03; /* Interrupt level for rx ints */
2091 2061
2092 /* 2062 /*
2093 * Attempt to set up all channels to something reasonable, and 2063 * Attempt to set up all channels to something reasonable, and
@@ -2095,11 +2065,11 @@ mvme167_serial_console_setup(int cflag)
2095 * the ammount of fiddling we have to do in normal running. 2065 * the ammount of fiddling we have to do in normal running.
2096 */ 2066 */
2097 2067
2098 for (ch = 3; ch >= 0 ; ch--) { 2068 for (ch = 3; ch >= 0; ch--) {
2099 base_addr[CyCAR] = (u_char)ch; 2069 base_addr[CyCAR] = (u_char) ch;
2100 base_addr[CyIER] = 0; 2070 base_addr[CyIER] = 0;
2101 base_addr[CyCMR] = CyASYNC; 2071 base_addr[CyCMR] = CyASYNC;
2102 base_addr[CyLICR] = (u_char)ch << 2; 2072 base_addr[CyLICR] = (u_char) ch << 2;
2103 base_addr[CyLIVR] = 0x5c; 2073 base_addr[CyLIVR] = 0x5c;
2104 base_addr[CyTCOR] = baud_co[spd]; 2074 base_addr[CyTCOR] = baud_co[spd];
2105 base_addr[CyTBPR] = baud_bpr[spd]; 2075 base_addr[CyTBPR] = baud_bpr[spd];
@@ -2118,29 +2088,30 @@ mvme167_serial_console_setup(int cflag)
2118 base_addr[CyCOR7] = 0; 2088 base_addr[CyCOR7] = 0;
2119 base_addr[CyRTPRL] = 2; 2089 base_addr[CyRTPRL] = 2;
2120 base_addr[CyRTPRH] = 0; 2090 base_addr[CyRTPRH] = 0;
2121 base_addr[CyMSVR1] = 0; 2091 base_addr[CyMSVR1] = 0;
2122 base_addr[CyMSVR2] = 0; 2092 base_addr[CyMSVR2] = 0;
2123 write_cy_cmd(base_addr,CyINIT_CHAN|CyDIS_RCVR|CyDIS_XMTR); 2093 write_cy_cmd(base_addr, CyINIT_CHAN | CyDIS_RCVR | CyDIS_XMTR);
2124 } 2094 }
2125 2095
2126 /* 2096 /*
2127 * Now do specials for channel zero.... 2097 * Now do specials for channel zero....
2128 */ 2098 */
2129 2099
2130 base_addr[CyMSVR1] = CyRTS; 2100 base_addr[CyMSVR1] = CyRTS;
2131 base_addr[CyMSVR2] = CyDTR; 2101 base_addr[CyMSVR2] = CyDTR;
2132 base_addr[CyIER] = CyRxData; 2102 base_addr[CyIER] = CyRxData;
2133 write_cy_cmd(base_addr,CyENB_RCVR|CyENB_XMTR); 2103 write_cy_cmd(base_addr, CyENB_RCVR | CyENB_XMTR);
2134 2104
2135 local_irq_restore(flags); 2105 local_irq_restore(flags);
2136 2106
2137 my_udelay(20000L); /* Let it all settle down */ 2107 my_udelay(20000L); /* Let it all settle down */
2138 2108
2139 printk("CD2401 initialised, chip is rev 0x%02x\n", base_addr[CyGFRCR]); 2109 printk("CD2401 initialised, chip is rev 0x%02x\n", base_addr[CyGFRCR]);
2140 if (badspeed) 2110 if (badspeed)
2141 printk(" WARNING: Failed to identify line speed, rcor=%02x,rbpr=%02x\n", 2111 printk
2142 rcor >> 5, rbpr); 2112 (" WARNING: Failed to identify line speed, rcor=%02x,rbpr=%02x\n",
2143} /* serial_console_init */ 2113 rcor >> 5, rbpr);
2114} /* serial_console_init */
2144 2115
2145static const struct tty_operations cy_ops = { 2116static const struct tty_operations cy_ops = {
2146 .open = cy_open, 2117 .open = cy_open,
@@ -2161,6 +2132,7 @@ static const struct tty_operations cy_ops = {
2161 .tiocmget = cy_tiocmget, 2132 .tiocmget = cy_tiocmget,
2162 .tiocmset = cy_tiocmset, 2133 .tiocmset = cy_tiocmset,
2163}; 2134};
2135
2164/* The serial driver boot-time initialization code! 2136/* The serial driver boot-time initialization code!
2165 Hardware I/O ports are mapped to character special devices on a 2137 Hardware I/O ports are mapped to character special devices on a
2166 first found, first allocated manner. That is, this code searches 2138 first found, first allocated manner. That is, this code searches
@@ -2177,214 +2149,214 @@ static const struct tty_operations cy_ops = {
2177 If there are more cards with more ports than have been statically 2149 If there are more cards with more ports than have been statically
2178 allocated above, a warning is printed and the extra ports are ignored. 2150 allocated above, a warning is printed and the extra ports are ignored.
2179 */ 2151 */
2180static int __init 2152static int __init serial167_init(void)
2181serial167_init(void)
2182{ 2153{
2183 struct cyclades_port *info; 2154 struct cyclades_port *info;
2184 int ret = 0; 2155 int ret = 0;
2185 int good_ports = 0; 2156 int good_ports = 0;
2186 int port_num = 0; 2157 int port_num = 0;
2187 int index; 2158 int index;
2188 int DefSpeed; 2159 int DefSpeed;
2189#ifdef notyet 2160#ifdef notyet
2190 struct sigaction sa; 2161 struct sigaction sa;
2191#endif 2162#endif
2192 2163
2193 if (!(mvme16x_config &MVME16x_CONFIG_GOT_CD2401)) 2164 if (!(mvme16x_config & MVME16x_CONFIG_GOT_CD2401))
2194 return 0; 2165 return 0;
2195 2166
2196 cy_serial_driver = alloc_tty_driver(NR_PORTS); 2167 cy_serial_driver = alloc_tty_driver(NR_PORTS);
2197 if (!cy_serial_driver) 2168 if (!cy_serial_driver)
2198 return -ENOMEM; 2169 return -ENOMEM;
2199 2170
2200#if 0 2171#if 0
2201scrn[1] = '\0'; 2172 scrn[1] = '\0';
2202#endif 2173#endif
2203 2174
2204 show_version(); 2175 show_version();
2205 2176
2206 /* Has "console=0,9600n8" been used in bootinfo to change speed? */ 2177 /* Has "console=0,9600n8" been used in bootinfo to change speed? */
2207 if (serial_console_cflag) 2178 if (serial_console_cflag)
2208 DefSpeed = serial_console_cflag & 0017; 2179 DefSpeed = serial_console_cflag & 0017;
2209 else { 2180 else {
2210 DefSpeed = initial_console_speed; 2181 DefSpeed = initial_console_speed;
2211 serial_console_info = &cy_port[0]; 2182 serial_console_info = &cy_port[0];
2212 serial_console_cflag = DefSpeed | CS8; 2183 serial_console_cflag = DefSpeed | CS8;
2213#if 0 2184#if 0
2214 serial_console = 64; /*callout_driver.minor_start*/ 2185 serial_console = 64; /*callout_driver.minor_start */
2215#endif 2186#endif
2216 } 2187 }
2217
2218 /* Initialize the tty_driver structure */
2219
2220 cy_serial_driver->owner = THIS_MODULE;
2221 cy_serial_driver->name = "ttyS";
2222 cy_serial_driver->major = TTY_MAJOR;
2223 cy_serial_driver->minor_start = 64;
2224 cy_serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
2225 cy_serial_driver->subtype = SERIAL_TYPE_NORMAL;
2226 cy_serial_driver->init_termios = tty_std_termios;
2227 cy_serial_driver->init_termios.c_cflag =
2228 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
2229 cy_serial_driver->flags = TTY_DRIVER_REAL_RAW;
2230 tty_set_operations(cy_serial_driver, &cy_ops);
2231 2188
2232 ret = tty_register_driver(cy_serial_driver); 2189 /* Initialize the tty_driver structure */
2233 if (ret) {
2234 printk(KERN_ERR "Couldn't register MVME166/7 serial driver\n");
2235 put_tty_driver(cy_serial_driver);
2236 return ret;
2237 }
2238 2190
2239 port_num = 0; 2191 cy_serial_driver->owner = THIS_MODULE;
2240 info = cy_port; 2192 cy_serial_driver->name = "ttyS";
2241 for (index = 0; index < 1; index++) { 2193 cy_serial_driver->major = TTY_MAJOR;
2194 cy_serial_driver->minor_start = 64;
2195 cy_serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
2196 cy_serial_driver->subtype = SERIAL_TYPE_NORMAL;
2197 cy_serial_driver->init_termios = tty_std_termios;
2198 cy_serial_driver->init_termios.c_cflag =
2199 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
2200 cy_serial_driver->flags = TTY_DRIVER_REAL_RAW;
2201 tty_set_operations(cy_serial_driver, &cy_ops);
2202
2203 ret = tty_register_driver(cy_serial_driver);
2204 if (ret) {
2205 printk(KERN_ERR "Couldn't register MVME166/7 serial driver\n");
2206 put_tty_driver(cy_serial_driver);
2207 return ret;
2208 }
2242 2209
2243 good_ports = 4; 2210 port_num = 0;
2211 info = cy_port;
2212 for (index = 0; index < 1; index++) {
2244 2213
2245 if(port_num < NR_PORTS){ 2214 good_ports = 4;
2246 while( good_ports-- && port_num < NR_PORTS){ 2215
2216 if (port_num < NR_PORTS) {
2217 while (good_ports-- && port_num < NR_PORTS) {
2247 /*** initialize port ***/ 2218 /*** initialize port ***/
2248 info->magic = CYCLADES_MAGIC; 2219 info->magic = CYCLADES_MAGIC;
2249 info->type = PORT_CIRRUS; 2220 info->type = PORT_CIRRUS;
2250 info->card = index; 2221 info->card = index;
2251 info->line = port_num; 2222 info->line = port_num;
2252 info->flags = STD_COM_FLAGS; 2223 info->flags = STD_COM_FLAGS;
2253 info->tty = NULL; 2224 info->tty = NULL;
2254 info->xmit_fifo_size = 12; 2225 info->xmit_fifo_size = 12;
2255 info->cor1 = CyPARITY_NONE|Cy_8_BITS; 2226 info->cor1 = CyPARITY_NONE | Cy_8_BITS;
2256 info->cor2 = CyETC; 2227 info->cor2 = CyETC;
2257 info->cor3 = Cy_1_STOP; 2228 info->cor3 = Cy_1_STOP;
2258 info->cor4 = 0x08; /* _very_ small receive threshold */ 2229 info->cor4 = 0x08; /* _very_ small receive threshold */
2259 info->cor5 = 0; 2230 info->cor5 = 0;
2260 info->cor6 = 0; 2231 info->cor6 = 0;
2261 info->cor7 = 0; 2232 info->cor7 = 0;
2262 info->tbpr = baud_bpr[DefSpeed]; /* Tx BPR */ 2233 info->tbpr = baud_bpr[DefSpeed]; /* Tx BPR */
2263 info->tco = baud_co[DefSpeed]; /* Tx CO */ 2234 info->tco = baud_co[DefSpeed]; /* Tx CO */
2264 info->rbpr = baud_bpr[DefSpeed]; /* Rx BPR */ 2235 info->rbpr = baud_bpr[DefSpeed]; /* Rx BPR */
2265 info->rco = baud_co[DefSpeed] >> 5; /* Rx CO */ 2236 info->rco = baud_co[DefSpeed] >> 5; /* Rx CO */
2266 info->close_delay = 0; 2237 info->close_delay = 0;
2267 info->x_char = 0; 2238 info->x_char = 0;
2268 info->event = 0; 2239 info->event = 0;
2269 info->count = 0; 2240 info->count = 0;
2270#ifdef SERIAL_DEBUG_COUNT 2241#ifdef SERIAL_DEBUG_COUNT
2271 printk("cyc: %d: setting count to 0\n", __LINE__); 2242 printk("cyc: %d: setting count to 0\n",
2272#endif 2243 __LINE__);
2273 info->blocked_open = 0; 2244#endif
2274 info->default_threshold = 0; 2245 info->blocked_open = 0;
2275 info->default_timeout = 0; 2246 info->default_threshold = 0;
2276 INIT_WORK(&info->tqueue, do_softint); 2247 info->default_timeout = 0;
2277 init_waitqueue_head(&info->open_wait); 2248 INIT_WORK(&info->tqueue, do_softint);
2278 init_waitqueue_head(&info->close_wait); 2249 init_waitqueue_head(&info->open_wait);
2279 /* info->session */ 2250 init_waitqueue_head(&info->close_wait);
2280 /* info->pgrp */ 2251 /* info->session */
2252 /* info->pgrp */
2281/*** !!!!!!!! this may expose new bugs !!!!!!!!! *********/ 2253/*** !!!!!!!! this may expose new bugs !!!!!!!!! *********/
2282 info->read_status_mask = CyTIMEOUT| CySPECHAR| CyBREAK 2254 info->read_status_mask =
2283 | CyPARITY| CyFRAME| CyOVERRUN; 2255 CyTIMEOUT | CySPECHAR | CyBREAK | CyPARITY |
2284 /* info->timeout */ 2256 CyFRAME | CyOVERRUN;
2285 2257 /* info->timeout */
2286 printk("ttyS%d ", info->line); 2258
2287 port_num++;info++; 2259 printk("ttyS%d ", info->line);
2288 if(!(port_num & 7)){ 2260 port_num++;
2289 printk("\n "); 2261 info++;
2262 if (!(port_num & 7)) {
2263 printk("\n ");
2264 }
2265 }
2290 } 2266 }
2291 } 2267 printk("\n");
2292 } 2268 }
2293 printk("\n"); 2269 while (port_num < NR_PORTS) {
2294 } 2270 info->line = -1;
2295 while( port_num < NR_PORTS){ 2271 port_num++;
2296 info->line = -1; 2272 info++;
2297 port_num++;info++; 2273 }
2298 }
2299#ifdef CONFIG_REMOTE_DEBUG 2274#ifdef CONFIG_REMOTE_DEBUG
2300 debug_setup(); 2275 debug_setup();
2301#endif 2276#endif
2302 ret = request_irq(MVME167_IRQ_SER_ERR, cd2401_rxerr_interrupt, 0, 2277 ret = request_irq(MVME167_IRQ_SER_ERR, cd2401_rxerr_interrupt, 0,
2303 "cd2401_errors", cd2401_rxerr_interrupt); 2278 "cd2401_errors", cd2401_rxerr_interrupt);
2304 if (ret) { 2279 if (ret) {
2305 printk(KERN_ERR "Could't get cd2401_errors IRQ"); 2280 printk(KERN_ERR "Could't get cd2401_errors IRQ");
2306 goto cleanup_serial_driver; 2281 goto cleanup_serial_driver;
2307 } 2282 }
2308 2283
2309 ret = request_irq(MVME167_IRQ_SER_MODEM, cd2401_modem_interrupt, 0, 2284 ret = request_irq(MVME167_IRQ_SER_MODEM, cd2401_modem_interrupt, 0,
2310 "cd2401_modem", cd2401_modem_interrupt); 2285 "cd2401_modem", cd2401_modem_interrupt);
2311 if (ret) { 2286 if (ret) {
2312 printk(KERN_ERR "Could't get cd2401_modem IRQ"); 2287 printk(KERN_ERR "Could't get cd2401_modem IRQ");
2313 goto cleanup_irq_cd2401_errors; 2288 goto cleanup_irq_cd2401_errors;
2314 } 2289 }
2315 2290
2316 ret = request_irq(MVME167_IRQ_SER_TX, cd2401_tx_interrupt, 0, 2291 ret = request_irq(MVME167_IRQ_SER_TX, cd2401_tx_interrupt, 0,
2317 "cd2401_txints", cd2401_tx_interrupt); 2292 "cd2401_txints", cd2401_tx_interrupt);
2318 if (ret) { 2293 if (ret) {
2319 printk(KERN_ERR "Could't get cd2401_txints IRQ"); 2294 printk(KERN_ERR "Could't get cd2401_txints IRQ");
2320 goto cleanup_irq_cd2401_modem; 2295 goto cleanup_irq_cd2401_modem;
2321 } 2296 }
2322 2297
2323 ret = request_irq(MVME167_IRQ_SER_RX, cd2401_rx_interrupt, 0, 2298 ret = request_irq(MVME167_IRQ_SER_RX, cd2401_rx_interrupt, 0,
2324 "cd2401_rxints", cd2401_rx_interrupt); 2299 "cd2401_rxints", cd2401_rx_interrupt);
2325 if (ret) { 2300 if (ret) {
2326 printk(KERN_ERR "Could't get cd2401_rxints IRQ"); 2301 printk(KERN_ERR "Could't get cd2401_rxints IRQ");
2327 goto cleanup_irq_cd2401_txints; 2302 goto cleanup_irq_cd2401_txints;
2328 } 2303 }
2329 2304
2330 /* Now we have registered the interrupt handlers, allow the interrupts */ 2305 /* Now we have registered the interrupt handlers, allow the interrupts */
2331 2306
2332 pcc2chip[PccSCCMICR] = 0x15; /* Serial ints are level 5 */ 2307 pcc2chip[PccSCCMICR] = 0x15; /* Serial ints are level 5 */
2333 pcc2chip[PccSCCTICR] = 0x15; 2308 pcc2chip[PccSCCTICR] = 0x15;
2334 pcc2chip[PccSCCRICR] = 0x15; 2309 pcc2chip[PccSCCRICR] = 0x15;
2335 2310
2336 pcc2chip[PccIMLR] = 3; /* Allow PCC2 ints above 3!? */ 2311 pcc2chip[PccIMLR] = 3; /* Allow PCC2 ints above 3!? */
2337 2312
2338 return 0; 2313 return 0;
2339cleanup_irq_cd2401_txints: 2314cleanup_irq_cd2401_txints:
2340 free_irq(MVME167_IRQ_SER_TX, cd2401_tx_interrupt); 2315 free_irq(MVME167_IRQ_SER_TX, cd2401_tx_interrupt);
2341cleanup_irq_cd2401_modem: 2316cleanup_irq_cd2401_modem:
2342 free_irq(MVME167_IRQ_SER_MODEM, cd2401_modem_interrupt); 2317 free_irq(MVME167_IRQ_SER_MODEM, cd2401_modem_interrupt);
2343cleanup_irq_cd2401_errors: 2318cleanup_irq_cd2401_errors:
2344 free_irq(MVME167_IRQ_SER_ERR, cd2401_rxerr_interrupt); 2319 free_irq(MVME167_IRQ_SER_ERR, cd2401_rxerr_interrupt);
2345cleanup_serial_driver: 2320cleanup_serial_driver:
2346 if (tty_unregister_driver(cy_serial_driver)) 2321 if (tty_unregister_driver(cy_serial_driver))
2347 printk(KERN_ERR "Couldn't unregister MVME166/7 serial driver\n"); 2322 printk(KERN_ERR
2348 put_tty_driver(cy_serial_driver); 2323 "Couldn't unregister MVME166/7 serial driver\n");
2349 return ret; 2324 put_tty_driver(cy_serial_driver);
2350} /* serial167_init */ 2325 return ret;
2326} /* serial167_init */
2351 2327
2352module_init(serial167_init); 2328module_init(serial167_init);
2353 2329
2354
2355#ifdef CYCLOM_SHOW_STATUS 2330#ifdef CYCLOM_SHOW_STATUS
2356static void 2331static void show_status(int line_num)
2357show_status(int line_num)
2358{ 2332{
2359 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 2333 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
2360 int channel; 2334 int channel;
2361 struct cyclades_port * info; 2335 struct cyclades_port *info;
2362 unsigned long flags; 2336 unsigned long flags;
2363 2337
2364 info = &cy_port[line_num]; 2338 info = &cy_port[line_num];
2365 channel = info->line; 2339 channel = info->line;
2366 printk(" channel %d\n", channel);/**/ 2340 printk(" channel %d\n", channel);
2367 2341 /**/ printk(" cy_port\n");
2368 printk(" cy_port\n"); 2342 printk(" card line flags = %d %d %x\n",
2369 printk(" card line flags = %d %d %x\n", 2343 info->card, info->line, info->flags);
2370 info->card, info->line, info->flags); 2344 printk
2371 printk(" *tty read_status_mask timeout xmit_fifo_size = %lx %x %x %x\n", 2345 (" *tty read_status_mask timeout xmit_fifo_size = %lx %x %x %x\n",
2372 (long)info->tty, info->read_status_mask, 2346 (long)info->tty, info->read_status_mask, info->timeout,
2373 info->timeout, info->xmit_fifo_size); 2347 info->xmit_fifo_size);
2374 printk(" cor1,cor2,cor3,cor4,cor5,cor6,cor7 = %x %x %x %x %x %x %x\n", 2348 printk(" cor1,cor2,cor3,cor4,cor5,cor6,cor7 = %x %x %x %x %x %x %x\n",
2375 info->cor1, info->cor2, info->cor3, info->cor4, info->cor5, 2349 info->cor1, info->cor2, info->cor3, info->cor4, info->cor5,
2376 info->cor6, info->cor7); 2350 info->cor6, info->cor7);
2377 printk(" tbpr,tco,rbpr,rco = %d %d %d %d\n", 2351 printk(" tbpr,tco,rbpr,rco = %d %d %d %d\n", info->tbpr, info->tco,
2378 info->tbpr, info->tco, info->rbpr, info->rco); 2352 info->rbpr, info->rco);
2379 printk(" close_delay event count = %d %d %d\n", 2353 printk(" close_delay event count = %d %d %d\n", info->close_delay,
2380 info->close_delay, info->event, info->count); 2354 info->event, info->count);
2381 printk(" x_char blocked_open = %x %x\n", 2355 printk(" x_char blocked_open = %x %x\n", info->x_char,
2382 info->x_char, info->blocked_open); 2356 info->blocked_open);
2383 printk(" open_wait = %lx %lx %lx\n", 2357 printk(" open_wait = %lx %lx %lx\n", (long)info->open_wait);
2384 (long)info->open_wait); 2358
2385 2359 local_irq_save(flags);
2386
2387 local_irq_save(flags);
2388 2360
2389/* Global Registers */ 2361/* Global Registers */
2390 2362
@@ -2398,7 +2370,7 @@ show_status(int line_num)
2398 printk(" CyMIR %x\n", base_addr[CyMIR]); 2370 printk(" CyMIR %x\n", base_addr[CyMIR]);
2399 printk(" CyTPR %x\n", base_addr[CyTPR]); 2371 printk(" CyTPR %x\n", base_addr[CyTPR]);
2400 2372
2401 base_addr[CyCAR] = (u_char)channel; 2373 base_addr[CyCAR] = (u_char) channel;
2402 2374
2403/* Virtual Registers */ 2375/* Virtual Registers */
2404 2376
@@ -2442,11 +2414,10 @@ show_status(int line_num)
2442 printk(" CyTBPR %x\n", base_addr[CyTBPR]); 2414 printk(" CyTBPR %x\n", base_addr[CyTBPR]);
2443 printk(" CyTCOR %x\n", base_addr[CyTCOR]); 2415 printk(" CyTCOR %x\n", base_addr[CyTCOR]);
2444 2416
2445 local_irq_restore(flags); 2417 local_irq_restore(flags);
2446} /* show_status */ 2418} /* show_status */
2447#endif 2419#endif
2448 2420
2449
2450#if 0 2421#if 0
2451/* Dummy routine in mvme16x/config.c for now */ 2422/* Dummy routine in mvme16x/config.c for now */
2452 2423
@@ -2459,61 +2430,67 @@ void console_setup(char *str, int *ints)
2459 int cflag = 0; 2430 int cflag = 0;
2460 2431
2461 /* Sanity check. */ 2432 /* Sanity check. */
2462 if (ints[0] > 3 || ints[1] > 3) return; 2433 if (ints[0] > 3 || ints[1] > 3)
2434 return;
2463 2435
2464 /* Get baud, bits and parity */ 2436 /* Get baud, bits and parity */
2465 baud = 2400; 2437 baud = 2400;
2466 bits = 8; 2438 bits = 8;
2467 parity = 'n'; 2439 parity = 'n';
2468 if (ints[2]) baud = ints[2]; 2440 if (ints[2])
2441 baud = ints[2];
2469 if ((s = strchr(str, ','))) { 2442 if ((s = strchr(str, ','))) {
2470 do { 2443 do {
2471 s++; 2444 s++;
2472 } while(*s >= '0' && *s <= '9'); 2445 } while (*s >= '0' && *s <= '9');
2473 if (*s) parity = *s++; 2446 if (*s)
2474 if (*s) bits = *s - '0'; 2447 parity = *s++;
2448 if (*s)
2449 bits = *s - '0';
2475 } 2450 }
2476 2451
2477 /* Now construct a cflag setting. */ 2452 /* Now construct a cflag setting. */
2478 switch(baud) { 2453 switch (baud) {
2479 case 1200: 2454 case 1200:
2480 cflag |= B1200; 2455 cflag |= B1200;
2481 break; 2456 break;
2482 case 9600: 2457 case 9600:
2483 cflag |= B9600; 2458 cflag |= B9600;
2484 break; 2459 break;
2485 case 19200: 2460 case 19200:
2486 cflag |= B19200; 2461 cflag |= B19200;
2487 break; 2462 break;
2488 case 38400: 2463 case 38400:
2489 cflag |= B38400; 2464 cflag |= B38400;
2490 break; 2465 break;
2491 case 2400: 2466 case 2400:
2492 default: 2467 default:
2493 cflag |= B2400; 2468 cflag |= B2400;
2494 break; 2469 break;
2495 } 2470 }
2496 switch(bits) { 2471 switch (bits) {
2497 case 7: 2472 case 7:
2498 cflag |= CS7; 2473 cflag |= CS7;
2499 break; 2474 break;
2500 default: 2475 default:
2501 case 8: 2476 case 8:
2502 cflag |= CS8; 2477 cflag |= CS8;
2503 break; 2478 break;
2504 } 2479 }
2505 switch(parity) { 2480 switch (parity) {
2506 case 'o': case 'O': 2481 case 'o':
2507 cflag |= PARODD; 2482 case 'O':
2508 break; 2483 cflag |= PARODD;
2509 case 'e': case 'E': 2484 break;
2510 cflag |= PARENB; 2485 case 'e':
2511 break; 2486 case 'E':
2487 cflag |= PARENB;
2488 break;
2512 } 2489 }
2513 2490
2514 serial_console_info = &cy_port[ints[1]]; 2491 serial_console_info = &cy_port[ints[1]];
2515 serial_console_cflag = cflag; 2492 serial_console_cflag = cflag;
2516 serial_console = ints[1] + 64; /*callout_driver.minor_start*/ 2493 serial_console = ints[1] + 64; /*callout_driver.minor_start */
2517} 2494}
2518#endif 2495#endif
2519 2496
@@ -2532,9 +2509,10 @@ void console_setup(char *str, int *ints)
2532 * The console must be locked when we get here. 2509 * The console must be locked when we get here.
2533 */ 2510 */
2534 2511
2535void serial167_console_write(struct console *co, const char *str, unsigned count) 2512void serial167_console_write(struct console *co, const char *str,
2513 unsigned count)
2536{ 2514{
2537 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 2515 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
2538 unsigned long flags; 2516 unsigned long flags;
2539 volatile u_char sink; 2517 volatile u_char sink;
2540 u_char ier; 2518 u_char ier;
@@ -2547,7 +2525,7 @@ void serial167_console_write(struct console *co, const char *str, unsigned count
2547 /* Ensure transmitter is enabled! */ 2525 /* Ensure transmitter is enabled! */
2548 2526
2549 port = 0; 2527 port = 0;
2550 base_addr[CyCAR] = (u_char)port; 2528 base_addr[CyCAR] = (u_char) port;
2551 while (base_addr[CyCCR]) 2529 while (base_addr[CyCCR])
2552 ; 2530 ;
2553 base_addr[CyCCR] = CyENB_XMTR; 2531 base_addr[CyCCR] = CyENB_XMTR;
@@ -2556,8 +2534,7 @@ void serial167_console_write(struct console *co, const char *str, unsigned count
2556 base_addr[CyIER] = CyTxMpty; 2534 base_addr[CyIER] = CyTxMpty;
2557 2535
2558 while (1) { 2536 while (1) {
2559 if (pcc2chip[PccSCCTICR] & 0x20) 2537 if (pcc2chip[PccSCCTICR] & 0x20) {
2560 {
2561 /* We have a Tx int. Acknowledge it */ 2538 /* We have a Tx int. Acknowledge it */
2562 sink = pcc2chip[PccTPIACKR]; 2539 sink = pcc2chip[PccTPIACKR];
2563 if ((base_addr[CyLICR] >> 2) == port) { 2540 if ((base_addr[CyLICR] >> 2) == port) {
@@ -2571,18 +2548,15 @@ void serial167_console_write(struct console *co, const char *str, unsigned count
2571 str++; 2548 str++;
2572 i++; 2549 i++;
2573 do_lf = 0; 2550 do_lf = 0;
2574 } 2551 } else if (*str == '\n') {
2575 else if (*str == '\n') {
2576 base_addr[CyTDR] = '\r'; 2552 base_addr[CyTDR] = '\r';
2577 do_lf = 1; 2553 do_lf = 1;
2578 } 2554 } else {
2579 else {
2580 base_addr[CyTDR] = *str++; 2555 base_addr[CyTDR] = *str++;
2581 i++; 2556 i++;
2582 } 2557 }
2583 base_addr[CyTEOIR] = 0; 2558 base_addr[CyTEOIR] = 0;
2584 } 2559 } else
2585 else
2586 base_addr[CyTEOIR] = CyNOTRANS; 2560 base_addr[CyTEOIR] = CyNOTRANS;
2587 } 2561 }
2588 } 2562 }
@@ -2592,45 +2566,44 @@ void serial167_console_write(struct console *co, const char *str, unsigned count
2592 local_irq_restore(flags); 2566 local_irq_restore(flags);
2593} 2567}
2594 2568
2595static struct tty_driver *serial167_console_device(struct console *c, int *index) 2569static struct tty_driver *serial167_console_device(struct console *c,
2570 int *index)
2596{ 2571{
2597 *index = c->index; 2572 *index = c->index;
2598 return cy_serial_driver; 2573 return cy_serial_driver;
2599} 2574}
2600 2575
2601
2602static int __init serial167_console_setup(struct console *co, char *options) 2576static int __init serial167_console_setup(struct console *co, char *options)
2603{ 2577{
2604 return 0; 2578 return 0;
2605} 2579}
2606 2580
2607
2608static struct console sercons = { 2581static struct console sercons = {
2609 .name = "ttyS", 2582 .name = "ttyS",
2610 .write = serial167_console_write, 2583 .write = serial167_console_write,
2611 .device = serial167_console_device, 2584 .device = serial167_console_device,
2612 .setup = serial167_console_setup, 2585 .setup = serial167_console_setup,
2613 .flags = CON_PRINTBUFFER, 2586 .flags = CON_PRINTBUFFER,
2614 .index = -1, 2587 .index = -1,
2615}; 2588};
2616 2589
2617
2618static int __init serial167_console_init(void) 2590static int __init serial167_console_init(void)
2619{ 2591{
2620 if (vme_brdtype == VME_TYPE_MVME166 || 2592 if (vme_brdtype == VME_TYPE_MVME166 ||
2621 vme_brdtype == VME_TYPE_MVME167 || 2593 vme_brdtype == VME_TYPE_MVME167 ||
2622 vme_brdtype == VME_TYPE_MVME177) { 2594 vme_brdtype == VME_TYPE_MVME177) {
2623 mvme167_serial_console_setup(0); 2595 mvme167_serial_console_setup(0);
2624 register_console(&sercons); 2596 register_console(&sercons);
2625 } 2597 }
2626 return 0; 2598 return 0;
2627} 2599}
2600
2628console_initcall(serial167_console_init); 2601console_initcall(serial167_console_init);
2629 2602
2630#ifdef CONFIG_REMOTE_DEBUG 2603#ifdef CONFIG_REMOTE_DEBUG
2631void putDebugChar (int c) 2604void putDebugChar(int c)
2632{ 2605{
2633 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 2606 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
2634 unsigned long flags; 2607 unsigned long flags;
2635 volatile u_char sink; 2608 volatile u_char sink;
2636 u_char ier; 2609 u_char ier;
@@ -2641,7 +2614,7 @@ void putDebugChar (int c)
2641 /* Ensure transmitter is enabled! */ 2614 /* Ensure transmitter is enabled! */
2642 2615
2643 port = DEBUG_PORT; 2616 port = DEBUG_PORT;
2644 base_addr[CyCAR] = (u_char)port; 2617 base_addr[CyCAR] = (u_char) port;
2645 while (base_addr[CyCCR]) 2618 while (base_addr[CyCCR])
2646 ; 2619 ;
2647 base_addr[CyCCR] = CyENB_XMTR; 2620 base_addr[CyCCR] = CyENB_XMTR;
@@ -2650,16 +2623,14 @@ void putDebugChar (int c)
2650 base_addr[CyIER] = CyTxMpty; 2623 base_addr[CyIER] = CyTxMpty;
2651 2624
2652 while (1) { 2625 while (1) {
2653 if (pcc2chip[PccSCCTICR] & 0x20) 2626 if (pcc2chip[PccSCCTICR] & 0x20) {
2654 {
2655 /* We have a Tx int. Acknowledge it */ 2627 /* We have a Tx int. Acknowledge it */
2656 sink = pcc2chip[PccTPIACKR]; 2628 sink = pcc2chip[PccTPIACKR];
2657 if ((base_addr[CyLICR] >> 2) == port) { 2629 if ((base_addr[CyLICR] >> 2) == port) {
2658 base_addr[CyTDR] = c; 2630 base_addr[CyTDR] = c;
2659 base_addr[CyTEOIR] = 0; 2631 base_addr[CyTEOIR] = 0;
2660 break; 2632 break;
2661 } 2633 } else
2662 else
2663 base_addr[CyTEOIR] = CyNOTRANS; 2634 base_addr[CyTEOIR] = CyNOTRANS;
2664 } 2635 }
2665 } 2636 }
@@ -2671,7 +2642,7 @@ void putDebugChar (int c)
2671 2642
2672int getDebugChar() 2643int getDebugChar()
2673{ 2644{
2674 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 2645 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
2675 unsigned long flags; 2646 unsigned long flags;
2676 volatile u_char sink; 2647 volatile u_char sink;
2677 u_char ier; 2648 u_char ier;
@@ -2693,7 +2664,7 @@ int getDebugChar()
2693 /* Ensure receiver is enabled! */ 2664 /* Ensure receiver is enabled! */
2694 2665
2695 port = DEBUG_PORT; 2666 port = DEBUG_PORT;
2696 base_addr[CyCAR] = (u_char)port; 2667 base_addr[CyCAR] = (u_char) port;
2697#if 0 2668#if 0
2698 while (base_addr[CyCCR]) 2669 while (base_addr[CyCCR])
2699 ; 2670 ;
@@ -2703,31 +2674,30 @@ int getDebugChar()
2703 base_addr[CyIER] = CyRxData; 2674 base_addr[CyIER] = CyRxData;
2704 2675
2705 while (1) { 2676 while (1) {
2706 if (pcc2chip[PccSCCRICR] & 0x20) 2677 if (pcc2chip[PccSCCRICR] & 0x20) {
2707 {
2708 /* We have a Rx int. Acknowledge it */ 2678 /* We have a Rx int. Acknowledge it */
2709 sink = pcc2chip[PccRPIACKR]; 2679 sink = pcc2chip[PccRPIACKR];
2710 if ((base_addr[CyLICR] >> 2) == port) { 2680 if ((base_addr[CyLICR] >> 2) == port) {
2711 int cnt = base_addr[CyRFOC]; 2681 int cnt = base_addr[CyRFOC];
2712 while (cnt-- > 0) 2682 while (cnt-- > 0) {
2713 {
2714 c = base_addr[CyRDR]; 2683 c = base_addr[CyRDR];
2715 if (c == 0) 2684 if (c == 0)
2716 printk ("!! debug char is null (cnt=%d) !!", cnt); 2685 printk
2686 ("!! debug char is null (cnt=%d) !!",
2687 cnt);
2717 else 2688 else
2718 queueDebugChar (c); 2689 queueDebugChar(c);
2719 } 2690 }
2720 base_addr[CyREOIR] = 0; 2691 base_addr[CyREOIR] = 0;
2721 i = debugiq.out; 2692 i = debugiq.out;
2722 if (i == debugiq.in) 2693 if (i == debugiq.in)
2723 panic ("Debug input queue empty!"); 2694 panic("Debug input queue empty!");
2724 c = debugiq.buf[i]; 2695 c = debugiq.buf[i];
2725 if (++i == DEBUG_LEN) 2696 if (++i == DEBUG_LEN)
2726 i = 0; 2697 i = 0;
2727 debugiq.out = i; 2698 debugiq.out = i;
2728 break; 2699 break;
2729 } 2700 } else
2730 else
2731 base_addr[CyREOIR] = CyNOTRANS; 2701 base_addr[CyREOIR] = CyNOTRANS;
2732 } 2702 }
2733 } 2703 }
@@ -2739,7 +2709,7 @@ int getDebugChar()
2739 return (c); 2709 return (c);
2740} 2710}
2741 2711
2742void queueDebugChar (int c) 2712void queueDebugChar(int c)
2743{ 2713{
2744 int i; 2714 int i;
2745 2715
@@ -2751,73 +2721,71 @@ void queueDebugChar (int c)
2751 debugiq.in = i; 2721 debugiq.in = i;
2752} 2722}
2753 2723
2754static void 2724static void debug_setup()
2755debug_setup()
2756{ 2725{
2757 unsigned long flags; 2726 unsigned long flags;
2758 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 2727 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
2759 int i, cflag; 2728 int i, cflag;
2760 2729
2761 cflag = B19200; 2730 cflag = B19200;
2762 2731
2763 local_irq_save(flags); 2732 local_irq_save(flags);
2764 2733
2765 for (i = 0; i < 4; i++) 2734 for (i = 0; i < 4; i++) {
2766 { 2735 base_addr[CyCAR] = i;
2767 base_addr[CyCAR] = i; 2736 base_addr[CyLICR] = i << 2;
2768 base_addr[CyLICR] = i << 2; 2737 }
2769 }
2770 2738
2771 debugiq.in = debugiq.out = 0; 2739 debugiq.in = debugiq.out = 0;
2772 2740
2773 base_addr[CyCAR] = DEBUG_PORT; 2741 base_addr[CyCAR] = DEBUG_PORT;
2774 2742
2775 /* baud rate */ 2743 /* baud rate */
2776 i = cflag & CBAUD; 2744 i = cflag & CBAUD;
2777 2745
2778 base_addr[CyIER] = 0; 2746 base_addr[CyIER] = 0;
2779 2747
2780 base_addr[CyCMR] = CyASYNC; 2748 base_addr[CyCMR] = CyASYNC;
2781 base_addr[CyLICR] = DEBUG_PORT << 2; 2749 base_addr[CyLICR] = DEBUG_PORT << 2;
2782 base_addr[CyLIVR] = 0x5c; 2750 base_addr[CyLIVR] = 0x5c;
2783 2751
2784 /* tx and rx baud rate */ 2752 /* tx and rx baud rate */
2785 2753
2786 base_addr[CyTCOR] = baud_co[i]; 2754 base_addr[CyTCOR] = baud_co[i];
2787 base_addr[CyTBPR] = baud_bpr[i]; 2755 base_addr[CyTBPR] = baud_bpr[i];
2788 base_addr[CyRCOR] = baud_co[i] >> 5; 2756 base_addr[CyRCOR] = baud_co[i] >> 5;
2789 base_addr[CyRBPR] = baud_bpr[i]; 2757 base_addr[CyRBPR] = baud_bpr[i];
2790 2758
2791 /* set line characteristics according configuration */ 2759 /* set line characteristics according configuration */
2792 2760
2793 base_addr[CySCHR1] = 0; 2761 base_addr[CySCHR1] = 0;
2794 base_addr[CySCHR2] = 0; 2762 base_addr[CySCHR2] = 0;
2795 base_addr[CySCRL] = 0; 2763 base_addr[CySCRL] = 0;
2796 base_addr[CySCRH] = 0; 2764 base_addr[CySCRH] = 0;
2797 base_addr[CyCOR1] = Cy_8_BITS | CyPARITY_NONE; 2765 base_addr[CyCOR1] = Cy_8_BITS | CyPARITY_NONE;
2798 base_addr[CyCOR2] = 0; 2766 base_addr[CyCOR2] = 0;
2799 base_addr[CyCOR3] = Cy_1_STOP; 2767 base_addr[CyCOR3] = Cy_1_STOP;
2800 base_addr[CyCOR4] = baud_cor4[i]; 2768 base_addr[CyCOR4] = baud_cor4[i];
2801 base_addr[CyCOR5] = 0; 2769 base_addr[CyCOR5] = 0;
2802 base_addr[CyCOR6] = 0; 2770 base_addr[CyCOR6] = 0;
2803 base_addr[CyCOR7] = 0; 2771 base_addr[CyCOR7] = 0;
2804 2772
2805 write_cy_cmd(base_addr,CyINIT_CHAN); 2773 write_cy_cmd(base_addr, CyINIT_CHAN);
2806 write_cy_cmd(base_addr,CyENB_RCVR); 2774 write_cy_cmd(base_addr, CyENB_RCVR);
2807 2775
2808 base_addr[CyCAR] = DEBUG_PORT; /* !!! Is this needed? */ 2776 base_addr[CyCAR] = DEBUG_PORT; /* !!! Is this needed? */
2809 2777
2810 base_addr[CyRTPRL] = 2; 2778 base_addr[CyRTPRL] = 2;
2811 base_addr[CyRTPRH] = 0; 2779 base_addr[CyRTPRH] = 0;
2812 2780
2813 base_addr[CyMSVR1] = CyRTS; 2781 base_addr[CyMSVR1] = CyRTS;
2814 base_addr[CyMSVR2] = CyDTR; 2782 base_addr[CyMSVR2] = CyDTR;
2815 2783
2816 base_addr[CyIER] = CyRxData; 2784 base_addr[CyIER] = CyRxData;
2817 2785
2818 local_irq_restore(flags); 2786 local_irq_restore(flags);
2819 2787
2820} /* debug_setup */ 2788} /* debug_setup */
2821 2789
2822#endif 2790#endif
2823 2791