| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * mcfserial.c -- serial driver for ColdFire internal UARTS. | 
|  | 3 | * | 
|  | 4 | * Copyright (C) 1999-2003 Greg Ungerer <gerg@snapgear.com> | 
|  | 5 | * Copyright (c) 2000-2001 Lineo, Inc. <www.lineo.com> | 
|  | 6 | * Copyright (C) 2001-2002 SnapGear Inc. <www.snapgear.com> | 
|  | 7 | * | 
|  | 8 | * Based on code from 68332serial.c which was: | 
|  | 9 | * | 
|  | 10 | * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) | 
|  | 11 | * Copyright (C) 1998 TSHG | 
|  | 12 | * Copyright (c) 1999 Rt-Control Inc. <jeff@uclinux.org> | 
|  | 13 | * | 
|  | 14 | * Changes: | 
|  | 15 | * 08/07/2003    Daniele Bellucci <bellucda@tiscali.it> | 
|  | 16 | *               some cleanups in mcfrs_write. | 
|  | 17 | * | 
|  | 18 | */ | 
|  | 19 |  | 
|  | 20 | #include <linux/module.h> | 
|  | 21 | #include <linux/errno.h> | 
|  | 22 | #include <linux/signal.h> | 
|  | 23 | #include <linux/sched.h> | 
|  | 24 | #include <linux/timer.h> | 
|  | 25 | #include <linux/wait.h> | 
|  | 26 | #include <linux/interrupt.h> | 
|  | 27 | #include <linux/tty.h> | 
|  | 28 | #include <linux/tty_flip.h> | 
|  | 29 | #include <linux/string.h> | 
|  | 30 | #include <linux/fcntl.h> | 
|  | 31 | #include <linux/mm.h> | 
|  | 32 | #include <linux/kernel.h> | 
|  | 33 | #include <linux/serial.h> | 
|  | 34 | #include <linux/serialP.h> | 
|  | 35 | #include <linux/console.h> | 
|  | 36 | #include <linux/init.h> | 
|  | 37 | #include <linux/bitops.h> | 
|  | 38 | #include <linux/delay.h> | 
|  | 39 |  | 
|  | 40 | #include <asm/io.h> | 
|  | 41 | #include <asm/irq.h> | 
|  | 42 | #include <asm/system.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #include <asm/semaphore.h> | 
|  | 44 | #include <asm/delay.h> | 
|  | 45 | #include <asm/coldfire.h> | 
|  | 46 | #include <asm/mcfsim.h> | 
|  | 47 | #include <asm/mcfuart.h> | 
|  | 48 | #include <asm/nettel.h> | 
|  | 49 | #include <asm/uaccess.h> | 
|  | 50 | #include "mcfserial.h" | 
|  | 51 |  | 
|  | 52 | struct timer_list mcfrs_timer_struct; | 
|  | 53 |  | 
|  | 54 | /* | 
|  | 55 | *	Default console baud rate,  we use this as the default | 
|  | 56 | *	for all ports so init can just open /dev/console and | 
|  | 57 | *	keep going.  Perhaps one day the cflag settings for the | 
|  | 58 | *	console can be used instead. | 
|  | 59 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #if defined(CONFIG_HW_FEITH) | 
| Greg Ungerer | b0433b9 | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 61 | #define	CONSOLE_BAUD_RATE	38400 | 
|  | 62 | #define	DEFAULT_CBAUD		B38400 | 
| Greg Ungerer | a8b8d57 | 2006-12-06 11:49:34 +1000 | [diff] [blame] | 63 | #elif defined(CONFIG_MOD5272) || defined(CONFIG_M5208EVB) || \ | 
|  | 64 | defined(CONFIG_M5329EVB) || defined(CONFIG_GILBARCO) | 
| Greg Ungerer | b0433b9 | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 65 | #define CONSOLE_BAUD_RATE 	115200 | 
|  | 66 | #define DEFAULT_CBAUD		B115200 | 
| Greg Ungerer | a9cdffb | 2006-02-08 09:19:17 +1000 | [diff] [blame] | 67 | #elif defined(CONFIG_ARNEWSH) || defined(CONFIG_FREESCALE) || \ | 
| Greg Ungerer | 76aa698 | 2006-06-26 10:33:10 +1000 | [diff] [blame] | 68 | defined(CONFIG_senTec) || defined(CONFIG_SNEHA) || defined(CONFIG_AVNET) | 
| Greg Ungerer | a9cdffb | 2006-02-08 09:19:17 +1000 | [diff] [blame] | 69 | #define	CONSOLE_BAUD_RATE	19200 | 
|  | 70 | #define	DEFAULT_CBAUD		B19200 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | #endif | 
|  | 72 |  | 
|  | 73 | #ifndef CONSOLE_BAUD_RATE | 
|  | 74 | #define	CONSOLE_BAUD_RATE	9600 | 
|  | 75 | #define	DEFAULT_CBAUD		B9600 | 
|  | 76 | #endif | 
|  | 77 |  | 
|  | 78 | int mcfrs_console_inited = 0; | 
|  | 79 | int mcfrs_console_port = -1; | 
|  | 80 | int mcfrs_console_baud = CONSOLE_BAUD_RATE; | 
|  | 81 | int mcfrs_console_cbaud = DEFAULT_CBAUD; | 
|  | 82 |  | 
|  | 83 | /* | 
|  | 84 | *	Driver data structures. | 
|  | 85 | */ | 
|  | 86 | static struct tty_driver *mcfrs_serial_driver; | 
|  | 87 |  | 
|  | 88 | /* number of characters left in xmit buffer before we ask for more */ | 
|  | 89 | #define WAKEUP_CHARS 256 | 
|  | 90 |  | 
|  | 91 | /* Debugging... | 
|  | 92 | */ | 
|  | 93 | #undef SERIAL_DEBUG_OPEN | 
|  | 94 | #undef SERIAL_DEBUG_FLOW | 
|  | 95 |  | 
| Greg Ungerer | 7f04d62 | 2005-11-07 14:09:50 +1000 | [diff] [blame] | 96 | #if defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x) || \ | 
| Greg Ungerer | 76aa698 | 2006-06-26 10:33:10 +1000 | [diff] [blame] | 97 | defined(CONFIG_M520x) || defined(CONFIG_M532x) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | #define	IRQBASE	(MCFINT_VECBASE+MCFINT_UART0) | 
|  | 99 | #else | 
|  | 100 | #define	IRQBASE	73 | 
|  | 101 | #endif | 
|  | 102 |  | 
|  | 103 | /* | 
|  | 104 | *	Configuration table, UARTs to look for at startup. | 
|  | 105 | */ | 
|  | 106 | static struct mcf_serial mcfrs_table[] = { | 
|  | 107 | {  /* ttyS0 */ | 
|  | 108 | .magic = 0, | 
|  | 109 | .addr = (volatile unsigned char *) (MCF_MBAR+MCFUART_BASE1), | 
|  | 110 | .irq = IRQBASE, | 
|  | 111 | .flags = ASYNC_BOOT_AUTOCONF, | 
|  | 112 | }, | 
| Greg Ungerer | a8b8d57 | 2006-12-06 11:49:34 +1000 | [diff] [blame] | 113 | #ifdef MCFUART_BASE2 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | {  /* ttyS1 */ | 
|  | 115 | .magic = 0, | 
|  | 116 | .addr = (volatile unsigned char *) (MCF_MBAR+MCFUART_BASE2), | 
|  | 117 | .irq = IRQBASE+1, | 
|  | 118 | .flags = ASYNC_BOOT_AUTOCONF, | 
|  | 119 | }, | 
| Greg Ungerer | a8b8d57 | 2006-12-06 11:49:34 +1000 | [diff] [blame] | 120 | #endif | 
|  | 121 | #ifdef MCFUART_BASE3 | 
|  | 122 | {  /* ttyS2 */ | 
|  | 123 | .magic = 0, | 
|  | 124 | .addr = (volatile unsigned char *) (MCF_MBAR+MCFUART_BASE3), | 
|  | 125 | .irq = IRQBASE+2, | 
|  | 126 | .flags = ASYNC_BOOT_AUTOCONF, | 
|  | 127 | }, | 
|  | 128 | #endif | 
|  | 129 | #ifdef MCFUART_BASE4 | 
|  | 130 | {  /* ttyS3 */ | 
|  | 131 | .magic = 0, | 
|  | 132 | .addr = (volatile unsigned char *) (MCF_MBAR+MCFUART_BASE4), | 
|  | 133 | .irq = IRQBASE+3, | 
|  | 134 | .flags = ASYNC_BOOT_AUTOCONF, | 
|  | 135 | }, | 
|  | 136 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | }; | 
|  | 138 |  | 
|  | 139 |  | 
|  | 140 | #define	NR_PORTS	(sizeof(mcfrs_table) / sizeof(struct mcf_serial)) | 
|  | 141 |  | 
|  | 142 | /* | 
|  | 143 | * This is used to figure out the divisor speeds and the timeouts. | 
|  | 144 | */ | 
|  | 145 | static int mcfrs_baud_table[] = { | 
|  | 146 | 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, | 
|  | 147 | 9600, 19200, 38400, 57600, 115200, 230400, 460800, 0 | 
|  | 148 | }; | 
|  | 149 | #define MCFRS_BAUD_TABLE_SIZE \ | 
|  | 150 | (sizeof(mcfrs_baud_table)/sizeof(mcfrs_baud_table[0])) | 
|  | 151 |  | 
|  | 152 |  | 
|  | 153 | #ifdef CONFIG_MAGIC_SYSRQ | 
|  | 154 | /* | 
|  | 155 | *	Magic system request keys. Used for debugging... | 
|  | 156 | */ | 
|  | 157 | extern int	magic_sysrq_key(int ch); | 
|  | 158 | #endif | 
|  | 159 |  | 
|  | 160 |  | 
|  | 161 | /* | 
|  | 162 | *	Forware declarations... | 
|  | 163 | */ | 
|  | 164 | static void	mcfrs_change_speed(struct mcf_serial *info); | 
|  | 165 | static void	mcfrs_wait_until_sent(struct tty_struct *tty, int timeout); | 
|  | 166 |  | 
|  | 167 |  | 
|  | 168 | static inline int serial_paranoia_check(struct mcf_serial *info, | 
|  | 169 | char *name, const char *routine) | 
|  | 170 | { | 
|  | 171 | #ifdef SERIAL_PARANOIA_CHECK | 
|  | 172 | static const char badmagic[] = | 
|  | 173 | "MCFRS(warning): bad magic number for serial struct %s in %s\n"; | 
|  | 174 | static const char badinfo[] = | 
|  | 175 | "MCFRS(warning): null mcf_serial for %s in %s\n"; | 
|  | 176 |  | 
|  | 177 | if (!info) { | 
|  | 178 | printk(badinfo, name, routine); | 
|  | 179 | return 1; | 
|  | 180 | } | 
|  | 181 | if (info->magic != SERIAL_MAGIC) { | 
|  | 182 | printk(badmagic, name, routine); | 
|  | 183 | return 1; | 
|  | 184 | } | 
|  | 185 | #endif | 
|  | 186 | return 0; | 
|  | 187 | } | 
|  | 188 |  | 
|  | 189 | /* | 
|  | 190 | *	Sets or clears DTR and RTS on the requested line. | 
|  | 191 | */ | 
|  | 192 | static void mcfrs_setsignals(struct mcf_serial *info, int dtr, int rts) | 
|  | 193 | { | 
|  | 194 | volatile unsigned char	*uartp; | 
|  | 195 | unsigned long		flags; | 
|  | 196 |  | 
|  | 197 | #if 0 | 
|  | 198 | printk("%s(%d): mcfrs_setsignals(info=%x,dtr=%d,rts=%d)\n", | 
|  | 199 | __FILE__, __LINE__, info, dtr, rts); | 
|  | 200 | #endif | 
|  | 201 |  | 
|  | 202 | local_irq_save(flags); | 
|  | 203 | if (dtr >= 0) { | 
|  | 204 | #ifdef MCFPP_DTR0 | 
|  | 205 | if (info->line) | 
|  | 206 | mcf_setppdata(MCFPP_DTR1, (dtr ? 0 : MCFPP_DTR1)); | 
|  | 207 | else | 
|  | 208 | mcf_setppdata(MCFPP_DTR0, (dtr ? 0 : MCFPP_DTR0)); | 
|  | 209 | #endif | 
|  | 210 | } | 
|  | 211 | if (rts >= 0) { | 
|  | 212 | uartp = info->addr; | 
|  | 213 | if (rts) { | 
|  | 214 | info->sigs |= TIOCM_RTS; | 
|  | 215 | uartp[MCFUART_UOP1] = MCFUART_UOP_RTS; | 
|  | 216 | } else { | 
|  | 217 | info->sigs &= ~TIOCM_RTS; | 
|  | 218 | uartp[MCFUART_UOP0] = MCFUART_UOP_RTS; | 
|  | 219 | } | 
|  | 220 | } | 
|  | 221 | local_irq_restore(flags); | 
|  | 222 | return; | 
|  | 223 | } | 
|  | 224 |  | 
|  | 225 | /* | 
|  | 226 | *	Gets values of serial signals. | 
|  | 227 | */ | 
|  | 228 | static int mcfrs_getsignals(struct mcf_serial *info) | 
|  | 229 | { | 
|  | 230 | volatile unsigned char	*uartp; | 
|  | 231 | unsigned long		flags; | 
|  | 232 | int			sigs; | 
|  | 233 | #if defined(CONFIG_NETtel) && defined(CONFIG_M5307) | 
|  | 234 | unsigned short		ppdata; | 
|  | 235 | #endif | 
|  | 236 |  | 
|  | 237 | #if 0 | 
|  | 238 | printk("%s(%d): mcfrs_getsignals(info=%x)\n", __FILE__, __LINE__); | 
|  | 239 | #endif | 
|  | 240 |  | 
|  | 241 | local_irq_save(flags); | 
|  | 242 | uartp = info->addr; | 
|  | 243 | sigs = (uartp[MCFUART_UIPR] & MCFUART_UIPR_CTS) ? 0 : TIOCM_CTS; | 
|  | 244 | sigs |= (info->sigs & TIOCM_RTS); | 
|  | 245 |  | 
|  | 246 | #ifdef MCFPP_DCD0 | 
|  | 247 | { | 
|  | 248 | unsigned int ppdata; | 
|  | 249 | ppdata = mcf_getppdata(); | 
|  | 250 | if (info->line == 0) { | 
|  | 251 | sigs |= (ppdata & MCFPP_DCD0) ? 0 : TIOCM_CD; | 
|  | 252 | sigs |= (ppdata & MCFPP_DTR0) ? 0 : TIOCM_DTR; | 
|  | 253 | } else if (info->line == 1) { | 
|  | 254 | sigs |= (ppdata & MCFPP_DCD1) ? 0 : TIOCM_CD; | 
|  | 255 | sigs |= (ppdata & MCFPP_DTR1) ? 0 : TIOCM_DTR; | 
|  | 256 | } | 
|  | 257 | } | 
|  | 258 | #endif | 
|  | 259 |  | 
|  | 260 | local_irq_restore(flags); | 
|  | 261 | return(sigs); | 
|  | 262 | } | 
|  | 263 |  | 
|  | 264 | /* | 
|  | 265 | * ------------------------------------------------------------ | 
|  | 266 | * mcfrs_stop() and mcfrs_start() | 
|  | 267 | * | 
|  | 268 | * This routines are called before setting or resetting tty->stopped. | 
|  | 269 | * They enable or disable transmitter interrupts, as necessary. | 
|  | 270 | * ------------------------------------------------------------ | 
|  | 271 | */ | 
|  | 272 | static void mcfrs_stop(struct tty_struct *tty) | 
|  | 273 | { | 
|  | 274 | volatile unsigned char	*uartp; | 
|  | 275 | struct mcf_serial	*info = (struct mcf_serial *)tty->driver_data; | 
|  | 276 | unsigned long		flags; | 
|  | 277 |  | 
|  | 278 | if (serial_paranoia_check(info, tty->name, "mcfrs_stop")) | 
|  | 279 | return; | 
|  | 280 |  | 
|  | 281 | local_irq_save(flags); | 
|  | 282 | uartp = info->addr; | 
|  | 283 | info->imr &= ~MCFUART_UIR_TXREADY; | 
|  | 284 | uartp[MCFUART_UIMR] = info->imr; | 
|  | 285 | local_irq_restore(flags); | 
|  | 286 | } | 
|  | 287 |  | 
|  | 288 | static void mcfrs_start(struct tty_struct *tty) | 
|  | 289 | { | 
|  | 290 | volatile unsigned char	*uartp; | 
|  | 291 | struct mcf_serial	*info = (struct mcf_serial *)tty->driver_data; | 
|  | 292 | unsigned long		flags; | 
|  | 293 |  | 
|  | 294 | if (serial_paranoia_check(info, tty->name, "mcfrs_start")) | 
|  | 295 | return; | 
|  | 296 |  | 
|  | 297 | local_irq_save(flags); | 
|  | 298 | if (info->xmit_cnt && info->xmit_buf) { | 
|  | 299 | uartp = info->addr; | 
|  | 300 | info->imr |= MCFUART_UIR_TXREADY; | 
|  | 301 | uartp[MCFUART_UIMR] = info->imr; | 
|  | 302 | } | 
|  | 303 | local_irq_restore(flags); | 
|  | 304 | } | 
|  | 305 |  | 
|  | 306 | /* | 
|  | 307 | * ---------------------------------------------------------------------- | 
|  | 308 | * | 
|  | 309 | * Here starts the interrupt handling routines.  All of the following | 
|  | 310 | * subroutines are declared as inline and are folded into | 
|  | 311 | * mcfrs_interrupt().  They were separated out for readability's sake. | 
|  | 312 | * | 
|  | 313 | * Note: mcfrs_interrupt() is a "fast" interrupt, which means that it | 
|  | 314 | * runs with interrupts turned off.  People who may want to modify | 
|  | 315 | * mcfrs_interrupt() should try to keep the interrupt handler as fast as | 
|  | 316 | * possible.  After you are done making modifications, it is not a bad | 
|  | 317 | * idea to do: | 
|  | 318 | * | 
|  | 319 | * gcc -S -DKERNEL -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer serial.c | 
|  | 320 | * | 
|  | 321 | * and look at the resulting assemble code in serial.s. | 
|  | 322 | * | 
|  | 323 | * 				- Ted Ts'o (tytso@mit.edu), 7-Mar-93 | 
|  | 324 | * ----------------------------------------------------------------------- | 
|  | 325 | */ | 
|  | 326 |  | 
|  | 327 | static inline void receive_chars(struct mcf_serial *info) | 
|  | 328 | { | 
|  | 329 | volatile unsigned char	*uartp; | 
|  | 330 | struct tty_struct	*tty = info->tty; | 
| Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 331 | unsigned char		status, ch, flag; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 |  | 
|  | 333 | if (!tty) | 
|  | 334 | return; | 
|  | 335 |  | 
|  | 336 | uartp = info->addr; | 
|  | 337 |  | 
|  | 338 | while ((status = uartp[MCFUART_USR]) & MCFUART_USR_RXREADY) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | ch = uartp[MCFUART_URB]; | 
|  | 340 | info->stats.rx++; | 
|  | 341 |  | 
|  | 342 | #ifdef CONFIG_MAGIC_SYSRQ | 
|  | 343 | if (mcfrs_console_inited && (info->line == mcfrs_console_port)) { | 
|  | 344 | if (magic_sysrq_key(ch)) | 
|  | 345 | continue; | 
|  | 346 | } | 
|  | 347 | #endif | 
|  | 348 |  | 
| Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 349 | flag = TTY_NORMAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | if (status & MCFUART_USR_RXERR) { | 
|  | 351 | uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETERR; | 
|  | 352 | if (status & MCFUART_USR_RXBREAK) { | 
|  | 353 | info->stats.rxbreak++; | 
| Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 354 | flag = TTY_BREAK; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | } else if (status & MCFUART_USR_RXPARITY) { | 
|  | 356 | info->stats.rxparity++; | 
| Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 357 | flag = TTY_PARITY; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | } else if (status & MCFUART_USR_RXOVERRUN) { | 
|  | 359 | info->stats.rxoverrun++; | 
| Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 360 | flag = TTY_OVERRUN; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | } else if (status & MCFUART_USR_RXFRAMING) { | 
|  | 362 | info->stats.rxframing++; | 
| Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 363 | flag = TTY_FRAME; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | } | 
| Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 366 | tty_insert_flip_char(tty, ch, flag); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | } | 
| Greg Ungerer | a9cdffb | 2006-02-08 09:19:17 +1000 | [diff] [blame] | 368 | tty_schedule_flip(tty); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | return; | 
|  | 370 | } | 
|  | 371 |  | 
|  | 372 | static inline void transmit_chars(struct mcf_serial *info) | 
|  | 373 | { | 
|  | 374 | volatile unsigned char	*uartp; | 
|  | 375 |  | 
|  | 376 | uartp = info->addr; | 
|  | 377 |  | 
|  | 378 | if (info->x_char) { | 
|  | 379 | /* Send special char - probably flow control */ | 
|  | 380 | uartp[MCFUART_UTB] = info->x_char; | 
|  | 381 | info->x_char = 0; | 
|  | 382 | info->stats.tx++; | 
|  | 383 | } | 
|  | 384 |  | 
|  | 385 | if ((info->xmit_cnt <= 0) || info->tty->stopped) { | 
|  | 386 | info->imr &= ~MCFUART_UIR_TXREADY; | 
|  | 387 | uartp[MCFUART_UIMR] = info->imr; | 
|  | 388 | return; | 
|  | 389 | } | 
|  | 390 |  | 
|  | 391 | while (uartp[MCFUART_USR] & MCFUART_USR_TXREADY) { | 
|  | 392 | uartp[MCFUART_UTB] = info->xmit_buf[info->xmit_tail++]; | 
|  | 393 | info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1); | 
|  | 394 | info->stats.tx++; | 
|  | 395 | if (--info->xmit_cnt <= 0) | 
|  | 396 | break; | 
|  | 397 | } | 
|  | 398 |  | 
|  | 399 | if (info->xmit_cnt < WAKEUP_CHARS) | 
|  | 400 | schedule_work(&info->tqueue); | 
|  | 401 | return; | 
|  | 402 | } | 
|  | 403 |  | 
|  | 404 | /* | 
|  | 405 | * This is the serial driver's generic interrupt routine | 
|  | 406 | */ | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 407 | irqreturn_t mcfrs_interrupt(int irq, void *dev_id) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | { | 
|  | 409 | struct mcf_serial	*info; | 
|  | 410 | unsigned char		isr; | 
|  | 411 |  | 
|  | 412 | info = &mcfrs_table[(irq - IRQBASE)]; | 
|  | 413 | isr = info->addr[MCFUART_UISR] & info->imr; | 
|  | 414 |  | 
|  | 415 | if (isr & MCFUART_UIR_RXREADY) | 
|  | 416 | receive_chars(info); | 
|  | 417 | if (isr & MCFUART_UIR_TXREADY) | 
|  | 418 | transmit_chars(info); | 
|  | 419 | return IRQ_HANDLED; | 
|  | 420 | } | 
|  | 421 |  | 
|  | 422 | /* | 
|  | 423 | * ------------------------------------------------------------------- | 
|  | 424 | * Here ends the serial interrupt routines. | 
|  | 425 | * ------------------------------------------------------------------- | 
|  | 426 | */ | 
|  | 427 |  | 
|  | 428 | static void mcfrs_offintr(void *private) | 
|  | 429 | { | 
|  | 430 | struct mcf_serial	*info = (struct mcf_serial *) private; | 
|  | 431 | struct tty_struct	*tty; | 
|  | 432 |  | 
|  | 433 | tty = info->tty; | 
|  | 434 | if (!tty) | 
|  | 435 | return; | 
|  | 436 | tty_wakeup(tty); | 
|  | 437 | } | 
|  | 438 |  | 
|  | 439 |  | 
|  | 440 | /* | 
|  | 441 | *	Change of state on a DCD line. | 
|  | 442 | */ | 
|  | 443 | void mcfrs_modem_change(struct mcf_serial *info, int dcd) | 
|  | 444 | { | 
|  | 445 | if (info->count == 0) | 
|  | 446 | return; | 
|  | 447 |  | 
|  | 448 | if (info->flags & ASYNC_CHECK_CD) { | 
|  | 449 | if (dcd) | 
|  | 450 | wake_up_interruptible(&info->open_wait); | 
|  | 451 | else | 
|  | 452 | schedule_work(&info->tqueue_hangup); | 
|  | 453 | } | 
|  | 454 | } | 
|  | 455 |  | 
|  | 456 |  | 
|  | 457 | #ifdef MCFPP_DCD0 | 
|  | 458 |  | 
|  | 459 | unsigned short	mcfrs_ppstatus; | 
|  | 460 |  | 
|  | 461 | /* | 
|  | 462 | * This subroutine is called when the RS_TIMER goes off. It is used | 
|  | 463 | * to monitor the state of the DCD lines - since they have no edge | 
|  | 464 | * sensors and interrupt generators. | 
|  | 465 | */ | 
|  | 466 | static void mcfrs_timer(void) | 
|  | 467 | { | 
|  | 468 | unsigned int	ppstatus, dcdval, i; | 
|  | 469 |  | 
|  | 470 | ppstatus = mcf_getppdata() & (MCFPP_DCD0 | MCFPP_DCD1); | 
|  | 471 |  | 
|  | 472 | if (ppstatus != mcfrs_ppstatus) { | 
|  | 473 | for (i = 0; (i < 2); i++) { | 
|  | 474 | dcdval = (i ? MCFPP_DCD1 : MCFPP_DCD0); | 
|  | 475 | if ((ppstatus & dcdval) != (mcfrs_ppstatus & dcdval)) { | 
|  | 476 | mcfrs_modem_change(&mcfrs_table[i], | 
|  | 477 | ((ppstatus & dcdval) ? 0 : 1)); | 
|  | 478 | } | 
|  | 479 | } | 
|  | 480 | } | 
|  | 481 | mcfrs_ppstatus = ppstatus; | 
|  | 482 |  | 
|  | 483 | /* Re-arm timer */ | 
|  | 484 | mcfrs_timer_struct.expires = jiffies + HZ/25; | 
|  | 485 | add_timer(&mcfrs_timer_struct); | 
|  | 486 | } | 
|  | 487 |  | 
|  | 488 | #endif	/* MCFPP_DCD0 */ | 
|  | 489 |  | 
|  | 490 |  | 
|  | 491 | /* | 
|  | 492 | * This routine is called from the scheduler tqueue when the interrupt | 
|  | 493 | * routine has signalled that a hangup has occurred. The path of | 
|  | 494 | * hangup processing is: | 
|  | 495 | * | 
|  | 496 | * 	serial interrupt routine -> (scheduler tqueue) -> | 
|  | 497 | * 	do_serial_hangup() -> tty->hangup() -> mcfrs_hangup() | 
|  | 498 | * | 
|  | 499 | */ | 
|  | 500 | static void do_serial_hangup(void *private) | 
|  | 501 | { | 
|  | 502 | struct mcf_serial	*info = (struct mcf_serial *) private; | 
|  | 503 | struct tty_struct	*tty; | 
|  | 504 |  | 
|  | 505 | tty = info->tty; | 
|  | 506 | if (!tty) | 
|  | 507 | return; | 
|  | 508 |  | 
|  | 509 | tty_hangup(tty); | 
|  | 510 | } | 
|  | 511 |  | 
|  | 512 | static int startup(struct mcf_serial * info) | 
|  | 513 | { | 
|  | 514 | volatile unsigned char	*uartp; | 
|  | 515 | unsigned long		flags; | 
|  | 516 |  | 
|  | 517 | if (info->flags & ASYNC_INITIALIZED) | 
|  | 518 | return 0; | 
|  | 519 |  | 
|  | 520 | if (!info->xmit_buf) { | 
|  | 521 | info->xmit_buf = (unsigned char *) __get_free_page(GFP_KERNEL); | 
|  | 522 | if (!info->xmit_buf) | 
|  | 523 | return -ENOMEM; | 
|  | 524 | } | 
|  | 525 |  | 
|  | 526 | local_irq_save(flags); | 
|  | 527 |  | 
|  | 528 | #ifdef SERIAL_DEBUG_OPEN | 
|  | 529 | printk("starting up ttyS%d (irq %d)...\n", info->line, info->irq); | 
|  | 530 | #endif | 
|  | 531 |  | 
|  | 532 | /* | 
|  | 533 | *	Reset UART, get it into known state... | 
|  | 534 | */ | 
|  | 535 | uartp = info->addr; | 
|  | 536 | uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETRX;  /* reset RX */ | 
|  | 537 | uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETTX;  /* reset TX */ | 
|  | 538 | mcfrs_setsignals(info, 1, 1); | 
|  | 539 |  | 
|  | 540 | if (info->tty) | 
|  | 541 | clear_bit(TTY_IO_ERROR, &info->tty->flags); | 
|  | 542 | info->xmit_cnt = info->xmit_head = info->xmit_tail = 0; | 
|  | 543 |  | 
|  | 544 | /* | 
|  | 545 | * and set the speed of the serial port | 
|  | 546 | */ | 
|  | 547 | mcfrs_change_speed(info); | 
|  | 548 |  | 
|  | 549 | /* | 
|  | 550 | * Lastly enable the UART transmitter and receiver, and | 
|  | 551 | * interrupt enables. | 
|  | 552 | */ | 
|  | 553 | info->imr = MCFUART_UIR_RXREADY; | 
|  | 554 | uartp[MCFUART_UCR] = MCFUART_UCR_RXENABLE | MCFUART_UCR_TXENABLE; | 
|  | 555 | uartp[MCFUART_UIMR] = info->imr; | 
|  | 556 |  | 
|  | 557 | info->flags |= ASYNC_INITIALIZED; | 
|  | 558 | local_irq_restore(flags); | 
|  | 559 | return 0; | 
|  | 560 | } | 
|  | 561 |  | 
|  | 562 | /* | 
|  | 563 | * This routine will shutdown a serial port; interrupts are disabled, and | 
|  | 564 | * DTR is dropped if the hangup on close termio flag is on. | 
|  | 565 | */ | 
|  | 566 | static void shutdown(struct mcf_serial * info) | 
|  | 567 | { | 
|  | 568 | volatile unsigned char	*uartp; | 
|  | 569 | unsigned long		flags; | 
|  | 570 |  | 
|  | 571 | if (!(info->flags & ASYNC_INITIALIZED)) | 
|  | 572 | return; | 
|  | 573 |  | 
|  | 574 | #ifdef SERIAL_DEBUG_OPEN | 
|  | 575 | printk("Shutting down serial port %d (irq %d)....\n", info->line, | 
|  | 576 | info->irq); | 
|  | 577 | #endif | 
|  | 578 |  | 
|  | 579 | local_irq_save(flags); | 
|  | 580 |  | 
|  | 581 | uartp = info->addr; | 
|  | 582 | uartp[MCFUART_UIMR] = 0;  /* mask all interrupts */ | 
|  | 583 | uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETRX;  /* reset RX */ | 
|  | 584 | uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETTX;  /* reset TX */ | 
|  | 585 |  | 
|  | 586 | if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) | 
|  | 587 | mcfrs_setsignals(info, 0, 0); | 
|  | 588 |  | 
|  | 589 | if (info->xmit_buf) { | 
|  | 590 | free_page((unsigned long) info->xmit_buf); | 
|  | 591 | info->xmit_buf = 0; | 
|  | 592 | } | 
|  | 593 |  | 
|  | 594 | if (info->tty) | 
|  | 595 | set_bit(TTY_IO_ERROR, &info->tty->flags); | 
|  | 596 |  | 
|  | 597 | info->flags &= ~ASYNC_INITIALIZED; | 
|  | 598 | local_irq_restore(flags); | 
|  | 599 | } | 
|  | 600 |  | 
|  | 601 |  | 
|  | 602 | /* | 
|  | 603 | * This routine is called to set the UART divisor registers to match | 
|  | 604 | * the specified baud rate for a serial port. | 
|  | 605 | */ | 
|  | 606 | static void mcfrs_change_speed(struct mcf_serial *info) | 
|  | 607 | { | 
|  | 608 | volatile unsigned char	*uartp; | 
|  | 609 | unsigned int		baudclk, cflag; | 
|  | 610 | unsigned long		flags; | 
|  | 611 | unsigned char		mr1, mr2; | 
|  | 612 | int			i; | 
|  | 613 | #ifdef	CONFIG_M5272 | 
|  | 614 | unsigned int		fraction; | 
|  | 615 | #endif | 
|  | 616 |  | 
|  | 617 | if (!info->tty || !info->tty->termios) | 
|  | 618 | return; | 
|  | 619 | cflag = info->tty->termios->c_cflag; | 
|  | 620 | if (info->addr == 0) | 
|  | 621 | return; | 
|  | 622 |  | 
|  | 623 | #if 0 | 
|  | 624 | printk("%s(%d): mcfrs_change_speed()\n", __FILE__, __LINE__); | 
|  | 625 | #endif | 
|  | 626 |  | 
|  | 627 | i = cflag & CBAUD; | 
|  | 628 | if (i & CBAUDEX) { | 
|  | 629 | i &= ~CBAUDEX; | 
|  | 630 | if (i < 1 || i > 4) | 
|  | 631 | info->tty->termios->c_cflag &= ~CBAUDEX; | 
|  | 632 | else | 
|  | 633 | i += 15; | 
|  | 634 | } | 
|  | 635 | if (i == 0) { | 
|  | 636 | mcfrs_setsignals(info, 0, -1); | 
|  | 637 | return; | 
|  | 638 | } | 
|  | 639 |  | 
|  | 640 | /* compute the baudrate clock */ | 
|  | 641 | #ifdef	CONFIG_M5272 | 
|  | 642 | /* | 
|  | 643 | * For the MCF5272, also compute the baudrate fraction. | 
|  | 644 | */ | 
|  | 645 | baudclk = (MCF_BUSCLK / mcfrs_baud_table[i]) / 32; | 
|  | 646 | fraction = MCF_BUSCLK - (baudclk * 32 * mcfrs_baud_table[i]); | 
|  | 647 | fraction *= 16; | 
|  | 648 | fraction /= (32 * mcfrs_baud_table[i]); | 
|  | 649 | #else | 
|  | 650 | baudclk = ((MCF_BUSCLK / mcfrs_baud_table[i]) + 16) / 32; | 
|  | 651 | #endif | 
|  | 652 |  | 
|  | 653 | info->baud = mcfrs_baud_table[i]; | 
|  | 654 |  | 
|  | 655 | mr1 = MCFUART_MR1_RXIRQRDY | MCFUART_MR1_RXERRCHAR; | 
|  | 656 | mr2 = 0; | 
|  | 657 |  | 
|  | 658 | switch (cflag & CSIZE) { | 
|  | 659 | case CS5:	mr1 |= MCFUART_MR1_CS5; break; | 
|  | 660 | case CS6:	mr1 |= MCFUART_MR1_CS6; break; | 
|  | 661 | case CS7:	mr1 |= MCFUART_MR1_CS7; break; | 
|  | 662 | case CS8: | 
|  | 663 | default:	mr1 |= MCFUART_MR1_CS8; break; | 
|  | 664 | } | 
|  | 665 |  | 
|  | 666 | if (cflag & PARENB) { | 
|  | 667 | if (cflag & CMSPAR) { | 
|  | 668 | if (cflag & PARODD) | 
|  | 669 | mr1 |= MCFUART_MR1_PARITYMARK; | 
|  | 670 | else | 
|  | 671 | mr1 |= MCFUART_MR1_PARITYSPACE; | 
|  | 672 | } else { | 
|  | 673 | if (cflag & PARODD) | 
|  | 674 | mr1 |= MCFUART_MR1_PARITYODD; | 
|  | 675 | else | 
|  | 676 | mr1 |= MCFUART_MR1_PARITYEVEN; | 
|  | 677 | } | 
|  | 678 | } else { | 
|  | 679 | mr1 |= MCFUART_MR1_PARITYNONE; | 
|  | 680 | } | 
|  | 681 |  | 
|  | 682 | if (cflag & CSTOPB) | 
|  | 683 | mr2 |= MCFUART_MR2_STOP2; | 
|  | 684 | else | 
|  | 685 | mr2 |= MCFUART_MR2_STOP1; | 
|  | 686 |  | 
|  | 687 | if (cflag & CRTSCTS) { | 
|  | 688 | mr1 |= MCFUART_MR1_RXRTS; | 
|  | 689 | mr2 |= MCFUART_MR2_TXCTS; | 
|  | 690 | } | 
|  | 691 |  | 
|  | 692 | if (cflag & CLOCAL) | 
|  | 693 | info->flags &= ~ASYNC_CHECK_CD; | 
|  | 694 | else | 
|  | 695 | info->flags |= ASYNC_CHECK_CD; | 
|  | 696 |  | 
|  | 697 | uartp = info->addr; | 
|  | 698 |  | 
|  | 699 | local_irq_save(flags); | 
|  | 700 | #if 0 | 
|  | 701 | printk("%s(%d): mr1=%x mr2=%x baudclk=%x\n", __FILE__, __LINE__, | 
|  | 702 | mr1, mr2, baudclk); | 
|  | 703 | #endif | 
|  | 704 | /* | 
|  | 705 | Note: pg 12-16 of MCF5206e User's Manual states that a | 
|  | 706 | software reset should be performed prior to changing | 
|  | 707 | UMR1,2, UCSR, UACR, bit 7 | 
|  | 708 | */ | 
|  | 709 | uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETRX;    /* reset RX */ | 
|  | 710 | uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETTX;    /* reset TX */ | 
|  | 711 | uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETMRPTR;	/* reset MR pointer */ | 
|  | 712 | uartp[MCFUART_UMR] = mr1; | 
|  | 713 | uartp[MCFUART_UMR] = mr2; | 
|  | 714 | uartp[MCFUART_UBG1] = (baudclk & 0xff00) >> 8;	/* set msb byte */ | 
|  | 715 | uartp[MCFUART_UBG2] = (baudclk & 0xff);		/* set lsb byte */ | 
|  | 716 | #ifdef	CONFIG_M5272 | 
|  | 717 | uartp[MCFUART_UFPD] = (fraction & 0xf);		/* set fraction */ | 
|  | 718 | #endif | 
|  | 719 | uartp[MCFUART_UCSR] = MCFUART_UCSR_RXCLKTIMER | MCFUART_UCSR_TXCLKTIMER; | 
|  | 720 | uartp[MCFUART_UCR] = MCFUART_UCR_RXENABLE | MCFUART_UCR_TXENABLE; | 
|  | 721 | mcfrs_setsignals(info, 1, -1); | 
|  | 722 | local_irq_restore(flags); | 
|  | 723 | return; | 
|  | 724 | } | 
|  | 725 |  | 
|  | 726 | static void mcfrs_flush_chars(struct tty_struct *tty) | 
|  | 727 | { | 
|  | 728 | volatile unsigned char	*uartp; | 
|  | 729 | struct mcf_serial	*info = (struct mcf_serial *)tty->driver_data; | 
|  | 730 | unsigned long		flags; | 
|  | 731 |  | 
|  | 732 | if (serial_paranoia_check(info, tty->name, "mcfrs_flush_chars")) | 
|  | 733 | return; | 
|  | 734 |  | 
|  | 735 | uartp = (volatile unsigned char *) info->addr; | 
|  | 736 |  | 
|  | 737 | /* | 
|  | 738 | * re-enable receiver interrupt | 
|  | 739 | */ | 
|  | 740 | local_irq_save(flags); | 
|  | 741 | if ((!(info->imr & MCFUART_UIR_RXREADY)) && | 
|  | 742 | (info->flags & ASYNC_INITIALIZED) ) { | 
|  | 743 | info->imr |= MCFUART_UIR_RXREADY; | 
|  | 744 | uartp[MCFUART_UIMR] = info->imr; | 
|  | 745 | } | 
|  | 746 | local_irq_restore(flags); | 
|  | 747 |  | 
|  | 748 | if (info->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped || | 
|  | 749 | !info->xmit_buf) | 
|  | 750 | return; | 
|  | 751 |  | 
|  | 752 | /* Enable transmitter */ | 
|  | 753 | local_irq_save(flags); | 
|  | 754 | info->imr |= MCFUART_UIR_TXREADY; | 
|  | 755 | uartp[MCFUART_UIMR] = info->imr; | 
|  | 756 | local_irq_restore(flags); | 
|  | 757 | } | 
|  | 758 |  | 
|  | 759 | static int mcfrs_write(struct tty_struct * tty, | 
|  | 760 | const unsigned char *buf, int count) | 
|  | 761 | { | 
|  | 762 | volatile unsigned char	*uartp; | 
|  | 763 | struct mcf_serial	*info = (struct mcf_serial *)tty->driver_data; | 
|  | 764 | unsigned long		flags; | 
|  | 765 | int			c, total = 0; | 
|  | 766 |  | 
|  | 767 | #if 0 | 
|  | 768 | printk("%s(%d): mcfrs_write(tty=%x,buf=%x,count=%d)\n", | 
|  | 769 | __FILE__, __LINE__, (int)tty, (int)buf, count); | 
|  | 770 | #endif | 
|  | 771 |  | 
|  | 772 | if (serial_paranoia_check(info, tty->name, "mcfrs_write")) | 
|  | 773 | return 0; | 
|  | 774 |  | 
|  | 775 | if (!tty || !info->xmit_buf) | 
|  | 776 | return 0; | 
|  | 777 |  | 
|  | 778 | local_save_flags(flags); | 
|  | 779 | while (1) { | 
|  | 780 | local_irq_disable(); | 
|  | 781 | c = min(count, (int) min(((int)SERIAL_XMIT_SIZE) - info->xmit_cnt - 1, | 
|  | 782 | ((int)SERIAL_XMIT_SIZE) - info->xmit_head)); | 
|  | 783 | local_irq_restore(flags); | 
|  | 784 |  | 
|  | 785 | if (c <= 0) | 
|  | 786 | break; | 
|  | 787 |  | 
|  | 788 | memcpy(info->xmit_buf + info->xmit_head, buf, c); | 
|  | 789 |  | 
|  | 790 | local_irq_disable(); | 
|  | 791 | info->xmit_head = (info->xmit_head + c) & (SERIAL_XMIT_SIZE-1); | 
|  | 792 | info->xmit_cnt += c; | 
|  | 793 | local_irq_restore(flags); | 
|  | 794 |  | 
|  | 795 | buf += c; | 
|  | 796 | count -= c; | 
|  | 797 | total += c; | 
|  | 798 | } | 
|  | 799 |  | 
|  | 800 | local_irq_disable(); | 
|  | 801 | uartp = info->addr; | 
|  | 802 | info->imr |= MCFUART_UIR_TXREADY; | 
|  | 803 | uartp[MCFUART_UIMR] = info->imr; | 
|  | 804 | local_irq_restore(flags); | 
|  | 805 |  | 
|  | 806 | return total; | 
|  | 807 | } | 
|  | 808 |  | 
|  | 809 | static int mcfrs_write_room(struct tty_struct *tty) | 
|  | 810 | { | 
|  | 811 | struct mcf_serial *info = (struct mcf_serial *)tty->driver_data; | 
|  | 812 | int	ret; | 
|  | 813 |  | 
|  | 814 | if (serial_paranoia_check(info, tty->name, "mcfrs_write_room")) | 
|  | 815 | return 0; | 
|  | 816 | ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1; | 
|  | 817 | if (ret < 0) | 
|  | 818 | ret = 0; | 
|  | 819 | return ret; | 
|  | 820 | } | 
|  | 821 |  | 
|  | 822 | static int mcfrs_chars_in_buffer(struct tty_struct *tty) | 
|  | 823 | { | 
|  | 824 | struct mcf_serial *info = (struct mcf_serial *)tty->driver_data; | 
|  | 825 |  | 
|  | 826 | if (serial_paranoia_check(info, tty->name, "mcfrs_chars_in_buffer")) | 
|  | 827 | return 0; | 
|  | 828 | return info->xmit_cnt; | 
|  | 829 | } | 
|  | 830 |  | 
|  | 831 | static void mcfrs_flush_buffer(struct tty_struct *tty) | 
|  | 832 | { | 
|  | 833 | struct mcf_serial	*info = (struct mcf_serial *)tty->driver_data; | 
|  | 834 | unsigned long		flags; | 
|  | 835 |  | 
|  | 836 | if (serial_paranoia_check(info, tty->name, "mcfrs_flush_buffer")) | 
|  | 837 | return; | 
|  | 838 |  | 
|  | 839 | local_irq_save(flags); | 
|  | 840 | info->xmit_cnt = info->xmit_head = info->xmit_tail = 0; | 
|  | 841 | local_irq_restore(flags); | 
|  | 842 |  | 
|  | 843 | tty_wakeup(tty); | 
|  | 844 | } | 
|  | 845 |  | 
|  | 846 | /* | 
|  | 847 | * ------------------------------------------------------------ | 
|  | 848 | * mcfrs_throttle() | 
|  | 849 | * | 
|  | 850 | * This routine is called by the upper-layer tty layer to signal that | 
|  | 851 | * incoming characters should be throttled. | 
|  | 852 | * ------------------------------------------------------------ | 
|  | 853 | */ | 
|  | 854 | static void mcfrs_throttle(struct tty_struct * tty) | 
|  | 855 | { | 
|  | 856 | struct mcf_serial *info = (struct mcf_serial *)tty->driver_data; | 
|  | 857 | #ifdef SERIAL_DEBUG_THROTTLE | 
|  | 858 | char	buf[64]; | 
|  | 859 |  | 
|  | 860 | printk("throttle %s: %d....\n", _tty_name(tty, buf), | 
|  | 861 | tty->ldisc.chars_in_buffer(tty)); | 
|  | 862 | #endif | 
|  | 863 |  | 
|  | 864 | if (serial_paranoia_check(info, tty->name, "mcfrs_throttle")) | 
|  | 865 | return; | 
|  | 866 |  | 
|  | 867 | if (I_IXOFF(tty)) | 
|  | 868 | info->x_char = STOP_CHAR(tty); | 
|  | 869 |  | 
|  | 870 | /* Turn off RTS line (do this atomic) */ | 
|  | 871 | } | 
|  | 872 |  | 
|  | 873 | static void mcfrs_unthrottle(struct tty_struct * tty) | 
|  | 874 | { | 
|  | 875 | struct mcf_serial *info = (struct mcf_serial *)tty->driver_data; | 
|  | 876 | #ifdef SERIAL_DEBUG_THROTTLE | 
|  | 877 | char	buf[64]; | 
|  | 878 |  | 
|  | 879 | printk("unthrottle %s: %d....\n", _tty_name(tty, buf), | 
|  | 880 | tty->ldisc.chars_in_buffer(tty)); | 
|  | 881 | #endif | 
|  | 882 |  | 
|  | 883 | if (serial_paranoia_check(info, tty->name, "mcfrs_unthrottle")) | 
|  | 884 | return; | 
|  | 885 |  | 
|  | 886 | if (I_IXOFF(tty)) { | 
|  | 887 | if (info->x_char) | 
|  | 888 | info->x_char = 0; | 
|  | 889 | else | 
|  | 890 | info->x_char = START_CHAR(tty); | 
|  | 891 | } | 
|  | 892 |  | 
|  | 893 | /* Assert RTS line (do this atomic) */ | 
|  | 894 | } | 
|  | 895 |  | 
|  | 896 | /* | 
|  | 897 | * ------------------------------------------------------------ | 
|  | 898 | * mcfrs_ioctl() and friends | 
|  | 899 | * ------------------------------------------------------------ | 
|  | 900 | */ | 
|  | 901 |  | 
|  | 902 | static int get_serial_info(struct mcf_serial * info, | 
|  | 903 | struct serial_struct * retinfo) | 
|  | 904 | { | 
|  | 905 | struct serial_struct tmp; | 
|  | 906 |  | 
|  | 907 | if (!retinfo) | 
|  | 908 | return -EFAULT; | 
|  | 909 | memset(&tmp, 0, sizeof(tmp)); | 
|  | 910 | tmp.type = info->type; | 
|  | 911 | tmp.line = info->line; | 
|  | 912 | tmp.port = (unsigned int) info->addr; | 
|  | 913 | tmp.irq = info->irq; | 
|  | 914 | tmp.flags = info->flags; | 
|  | 915 | tmp.baud_base = info->baud_base; | 
|  | 916 | tmp.close_delay = info->close_delay; | 
|  | 917 | tmp.closing_wait = info->closing_wait; | 
|  | 918 | tmp.custom_divisor = info->custom_divisor; | 
|  | 919 | return copy_to_user(retinfo,&tmp,sizeof(*retinfo)) ? -EFAULT : 0; | 
|  | 920 | } | 
|  | 921 |  | 
|  | 922 | static int set_serial_info(struct mcf_serial * info, | 
|  | 923 | struct serial_struct * new_info) | 
|  | 924 | { | 
|  | 925 | struct serial_struct new_serial; | 
|  | 926 | struct mcf_serial old_info; | 
|  | 927 | int 	retval = 0; | 
|  | 928 |  | 
|  | 929 | if (!new_info) | 
|  | 930 | return -EFAULT; | 
|  | 931 | if (copy_from_user(&new_serial,new_info,sizeof(new_serial))) | 
|  | 932 | return -EFAULT; | 
|  | 933 | old_info = *info; | 
|  | 934 |  | 
|  | 935 | if (!capable(CAP_SYS_ADMIN)) { | 
|  | 936 | if ((new_serial.baud_base != info->baud_base) || | 
|  | 937 | (new_serial.type != info->type) || | 
|  | 938 | (new_serial.close_delay != info->close_delay) || | 
|  | 939 | ((new_serial.flags & ~ASYNC_USR_MASK) != | 
|  | 940 | (info->flags & ~ASYNC_USR_MASK))) | 
|  | 941 | return -EPERM; | 
|  | 942 | info->flags = ((info->flags & ~ASYNC_USR_MASK) | | 
|  | 943 | (new_serial.flags & ASYNC_USR_MASK)); | 
|  | 944 | info->custom_divisor = new_serial.custom_divisor; | 
|  | 945 | goto check_and_exit; | 
|  | 946 | } | 
|  | 947 |  | 
|  | 948 | if (info->count > 1) | 
|  | 949 | return -EBUSY; | 
|  | 950 |  | 
|  | 951 | /* | 
|  | 952 | * OK, past this point, all the error checking has been done. | 
|  | 953 | * At this point, we start making changes..... | 
|  | 954 | */ | 
|  | 955 |  | 
|  | 956 | info->baud_base = new_serial.baud_base; | 
|  | 957 | info->flags = ((info->flags & ~ASYNC_FLAGS) | | 
|  | 958 | (new_serial.flags & ASYNC_FLAGS)); | 
|  | 959 | info->type = new_serial.type; | 
|  | 960 | info->close_delay = new_serial.close_delay; | 
|  | 961 | info->closing_wait = new_serial.closing_wait; | 
|  | 962 |  | 
|  | 963 | check_and_exit: | 
|  | 964 | retval = startup(info); | 
|  | 965 | return retval; | 
|  | 966 | } | 
|  | 967 |  | 
|  | 968 | /* | 
|  | 969 | * get_lsr_info - get line status register info | 
|  | 970 | * | 
|  | 971 | * Purpose: Let user call ioctl() to get info when the UART physically | 
|  | 972 | * 	    is emptied.  On bus types like RS485, the transmitter must | 
|  | 973 | * 	    release the bus after transmitting. This must be done when | 
|  | 974 | * 	    the transmit shift register is empty, not be done when the | 
|  | 975 | * 	    transmit holding register is empty.  This functionality | 
|  | 976 | * 	    allows an RS485 driver to be written in user space. | 
|  | 977 | */ | 
|  | 978 | static int get_lsr_info(struct mcf_serial * info, unsigned int *value) | 
|  | 979 | { | 
|  | 980 | volatile unsigned char	*uartp; | 
|  | 981 | unsigned long		flags; | 
|  | 982 | unsigned char		status; | 
|  | 983 |  | 
|  | 984 | local_irq_save(flags); | 
|  | 985 | uartp = info->addr; | 
|  | 986 | status = (uartp[MCFUART_USR] & MCFUART_USR_TXEMPTY) ? TIOCSER_TEMT : 0; | 
|  | 987 | local_irq_restore(flags); | 
|  | 988 |  | 
|  | 989 | return put_user(status,value); | 
|  | 990 | } | 
|  | 991 |  | 
|  | 992 | /* | 
|  | 993 | * This routine sends a break character out the serial port. | 
|  | 994 | */ | 
|  | 995 | static void send_break(	struct mcf_serial * info, int duration) | 
|  | 996 | { | 
|  | 997 | volatile unsigned char	*uartp; | 
|  | 998 | unsigned long		flags; | 
|  | 999 |  | 
|  | 1000 | if (!info->addr) | 
|  | 1001 | return; | 
|  | 1002 | set_current_state(TASK_INTERRUPTIBLE); | 
|  | 1003 | uartp = info->addr; | 
|  | 1004 |  | 
|  | 1005 | local_irq_save(flags); | 
|  | 1006 | uartp[MCFUART_UCR] = MCFUART_UCR_CMDBREAKSTART; | 
|  | 1007 | schedule_timeout(duration); | 
|  | 1008 | uartp[MCFUART_UCR] = MCFUART_UCR_CMDBREAKSTOP; | 
|  | 1009 | local_irq_restore(flags); | 
|  | 1010 | } | 
|  | 1011 |  | 
|  | 1012 | static int mcfrs_tiocmget(struct tty_struct *tty, struct file *file) | 
|  | 1013 | { | 
|  | 1014 | struct mcf_serial * info = (struct mcf_serial *)tty->driver_data; | 
|  | 1015 |  | 
|  | 1016 | if (serial_paranoia_check(info, tty->name, "mcfrs_ioctl")) | 
|  | 1017 | return -ENODEV; | 
|  | 1018 | if (tty->flags & (1 << TTY_IO_ERROR)) | 
|  | 1019 | return -EIO; | 
|  | 1020 |  | 
|  | 1021 | return mcfrs_getsignals(info); | 
|  | 1022 | } | 
|  | 1023 |  | 
|  | 1024 | static int mcfrs_tiocmset(struct tty_struct *tty, struct file *file, | 
|  | 1025 | unsigned int set, unsigned int clear) | 
|  | 1026 | { | 
|  | 1027 | struct mcf_serial * info = (struct mcf_serial *)tty->driver_data; | 
|  | 1028 | int rts = -1, dtr = -1; | 
|  | 1029 |  | 
|  | 1030 | if (serial_paranoia_check(info, tty->name, "mcfrs_ioctl")) | 
|  | 1031 | return -ENODEV; | 
|  | 1032 | if (tty->flags & (1 << TTY_IO_ERROR)) | 
|  | 1033 | return -EIO; | 
|  | 1034 |  | 
|  | 1035 | if (set & TIOCM_RTS) | 
|  | 1036 | rts = 1; | 
|  | 1037 | if (set & TIOCM_DTR) | 
|  | 1038 | dtr = 1; | 
|  | 1039 | if (clear & TIOCM_RTS) | 
|  | 1040 | rts = 0; | 
|  | 1041 | if (clear & TIOCM_DTR) | 
|  | 1042 | dtr = 0; | 
|  | 1043 |  | 
|  | 1044 | mcfrs_setsignals(info, dtr, rts); | 
|  | 1045 |  | 
|  | 1046 | return 0; | 
|  | 1047 | } | 
|  | 1048 |  | 
|  | 1049 | static int mcfrs_ioctl(struct tty_struct *tty, struct file * file, | 
|  | 1050 | unsigned int cmd, unsigned long arg) | 
|  | 1051 | { | 
|  | 1052 | struct mcf_serial * info = (struct mcf_serial *)tty->driver_data; | 
|  | 1053 | int retval, error; | 
|  | 1054 |  | 
|  | 1055 | if (serial_paranoia_check(info, tty->name, "mcfrs_ioctl")) | 
|  | 1056 | return -ENODEV; | 
|  | 1057 |  | 
|  | 1058 | if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) && | 
|  | 1059 | (cmd != TIOCSERCONFIG) && (cmd != TIOCSERGWILD)  && | 
|  | 1060 | (cmd != TIOCSERSWILD) && (cmd != TIOCSERGSTRUCT)) { | 
|  | 1061 | if (tty->flags & (1 << TTY_IO_ERROR)) | 
|  | 1062 | return -EIO; | 
|  | 1063 | } | 
|  | 1064 |  | 
|  | 1065 | switch (cmd) { | 
|  | 1066 | case TCSBRK:	/* SVID version: non-zero arg --> no break */ | 
|  | 1067 | retval = tty_check_change(tty); | 
|  | 1068 | if (retval) | 
|  | 1069 | return retval; | 
|  | 1070 | tty_wait_until_sent(tty, 0); | 
|  | 1071 | if (!arg) | 
|  | 1072 | send_break(info, HZ/4);	/* 1/4 second */ | 
|  | 1073 | return 0; | 
|  | 1074 | case TCSBRKP:	/* support for POSIX tcsendbreak() */ | 
|  | 1075 | retval = tty_check_change(tty); | 
|  | 1076 | if (retval) | 
|  | 1077 | return retval; | 
|  | 1078 | tty_wait_until_sent(tty, 0); | 
|  | 1079 | send_break(info, arg ? arg*(HZ/10) : HZ/4); | 
|  | 1080 | return 0; | 
|  | 1081 | case TIOCGSOFTCAR: | 
|  | 1082 | error = put_user(C_CLOCAL(tty) ? 1 : 0, | 
|  | 1083 | (unsigned long *) arg); | 
|  | 1084 | if (error) | 
|  | 1085 | return error; | 
|  | 1086 | return 0; | 
|  | 1087 | case TIOCSSOFTCAR: | 
|  | 1088 | get_user(arg, (unsigned long *) arg); | 
|  | 1089 | tty->termios->c_cflag = | 
|  | 1090 | ((tty->termios->c_cflag & ~CLOCAL) | | 
|  | 1091 | (arg ? CLOCAL : 0)); | 
|  | 1092 | return 0; | 
|  | 1093 | case TIOCGSERIAL: | 
|  | 1094 | if (access_ok(VERIFY_WRITE, (void *) arg, | 
|  | 1095 | sizeof(struct serial_struct))) | 
|  | 1096 | return get_serial_info(info, | 
|  | 1097 | (struct serial_struct *) arg); | 
|  | 1098 | return -EFAULT; | 
|  | 1099 | case TIOCSSERIAL: | 
|  | 1100 | return set_serial_info(info, | 
|  | 1101 | (struct serial_struct *) arg); | 
|  | 1102 | case TIOCSERGETLSR: /* Get line status register */ | 
|  | 1103 | if (access_ok(VERIFY_WRITE, (void *) arg, | 
|  | 1104 | sizeof(unsigned int))) | 
|  | 1105 | return get_lsr_info(info, (unsigned int *) arg); | 
|  | 1106 | return -EFAULT; | 
|  | 1107 | case TIOCSERGSTRUCT: | 
|  | 1108 | error = copy_to_user((struct mcf_serial *) arg, | 
|  | 1109 | info, sizeof(struct mcf_serial)); | 
|  | 1110 | if (error) | 
|  | 1111 | return -EFAULT; | 
|  | 1112 | return 0; | 
|  | 1113 |  | 
|  | 1114 | #ifdef TIOCSET422 | 
|  | 1115 | case TIOCSET422: { | 
|  | 1116 | unsigned int val; | 
|  | 1117 | get_user(val, (unsigned int *) arg); | 
|  | 1118 | mcf_setpa(MCFPP_PA11, (val ? 0 : MCFPP_PA11)); | 
|  | 1119 | break; | 
|  | 1120 | } | 
|  | 1121 | case TIOCGET422: { | 
|  | 1122 | unsigned int val; | 
|  | 1123 | val = (mcf_getpa() & MCFPP_PA11) ? 0 : 1; | 
|  | 1124 | put_user(val, (unsigned int *) arg); | 
|  | 1125 | break; | 
|  | 1126 | } | 
|  | 1127 | #endif | 
|  | 1128 |  | 
|  | 1129 | default: | 
|  | 1130 | return -ENOIOCTLCMD; | 
|  | 1131 | } | 
|  | 1132 | return 0; | 
|  | 1133 | } | 
|  | 1134 |  | 
| Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 1135 | static void mcfrs_set_termios(struct tty_struct *tty, struct ktermios *old_termios) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1136 | { | 
|  | 1137 | struct mcf_serial *info = (struct mcf_serial *)tty->driver_data; | 
|  | 1138 |  | 
|  | 1139 | if (tty->termios->c_cflag == old_termios->c_cflag) | 
|  | 1140 | return; | 
|  | 1141 |  | 
|  | 1142 | mcfrs_change_speed(info); | 
|  | 1143 |  | 
|  | 1144 | if ((old_termios->c_cflag & CRTSCTS) && | 
|  | 1145 | !(tty->termios->c_cflag & CRTSCTS)) { | 
|  | 1146 | tty->hw_stopped = 0; | 
|  | 1147 | mcfrs_setsignals(info, -1, 1); | 
|  | 1148 | #if 0 | 
|  | 1149 | mcfrs_start(tty); | 
|  | 1150 | #endif | 
|  | 1151 | } | 
|  | 1152 | } | 
|  | 1153 |  | 
|  | 1154 | /* | 
|  | 1155 | * ------------------------------------------------------------ | 
|  | 1156 | * mcfrs_close() | 
|  | 1157 | * | 
|  | 1158 | * This routine is called when the serial port gets closed.  First, we | 
|  | 1159 | * wait for the last remaining data to be sent.  Then, we unlink its | 
|  | 1160 | * S structure from the interrupt chain if necessary, and we free | 
|  | 1161 | * that IRQ if nothing is left in the chain. | 
|  | 1162 | * ------------------------------------------------------------ | 
|  | 1163 | */ | 
|  | 1164 | static void mcfrs_close(struct tty_struct *tty, struct file * filp) | 
|  | 1165 | { | 
|  | 1166 | volatile unsigned char	*uartp; | 
|  | 1167 | struct mcf_serial	*info = (struct mcf_serial *)tty->driver_data; | 
|  | 1168 | unsigned long		flags; | 
|  | 1169 |  | 
|  | 1170 | if (!info || serial_paranoia_check(info, tty->name, "mcfrs_close")) | 
|  | 1171 | return; | 
|  | 1172 |  | 
|  | 1173 | local_irq_save(flags); | 
|  | 1174 |  | 
|  | 1175 | if (tty_hung_up_p(filp)) { | 
|  | 1176 | local_irq_restore(flags); | 
|  | 1177 | return; | 
|  | 1178 | } | 
|  | 1179 |  | 
|  | 1180 | #ifdef SERIAL_DEBUG_OPEN | 
|  | 1181 | printk("mcfrs_close ttyS%d, count = %d\n", info->line, info->count); | 
|  | 1182 | #endif | 
|  | 1183 | if ((tty->count == 1) && (info->count != 1)) { | 
|  | 1184 | /* | 
|  | 1185 | * Uh, oh.  tty->count is 1, which means that the tty | 
|  | 1186 | * structure will be freed.  Info->count should always | 
|  | 1187 | * be one in these conditions.  If it's greater than | 
|  | 1188 | * one, we've got real problems, since it means the | 
|  | 1189 | * serial port won't be shutdown. | 
|  | 1190 | */ | 
|  | 1191 | printk("MCFRS: bad serial port count; tty->count is 1, " | 
|  | 1192 | "info->count is %d\n", info->count); | 
|  | 1193 | info->count = 1; | 
|  | 1194 | } | 
|  | 1195 | if (--info->count < 0) { | 
|  | 1196 | printk("MCFRS: bad serial port count for ttyS%d: %d\n", | 
|  | 1197 | info->line, info->count); | 
|  | 1198 | info->count = 0; | 
|  | 1199 | } | 
|  | 1200 | if (info->count) { | 
|  | 1201 | local_irq_restore(flags); | 
|  | 1202 | return; | 
|  | 1203 | } | 
|  | 1204 | info->flags |= ASYNC_CLOSING; | 
|  | 1205 |  | 
|  | 1206 | /* | 
|  | 1207 | * Now we wait for the transmit buffer to clear; and we notify | 
|  | 1208 | * the line discipline to only process XON/XOFF characters. | 
|  | 1209 | */ | 
|  | 1210 | tty->closing = 1; | 
|  | 1211 | if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE) | 
|  | 1212 | tty_wait_until_sent(tty, info->closing_wait); | 
|  | 1213 |  | 
|  | 1214 | /* | 
|  | 1215 | * At this point we stop accepting input.  To do this, we | 
|  | 1216 | * disable the receive line status interrupts, and tell the | 
|  | 1217 | * interrupt driver to stop checking the data ready bit in the | 
|  | 1218 | * line status register. | 
|  | 1219 | */ | 
|  | 1220 | info->imr &= ~MCFUART_UIR_RXREADY; | 
|  | 1221 | uartp = info->addr; | 
|  | 1222 | uartp[MCFUART_UIMR] = info->imr; | 
|  | 1223 |  | 
|  | 1224 | #if 0 | 
|  | 1225 | /* FIXME: do we need to keep this enabled for console?? */ | 
|  | 1226 | if (mcfrs_console_inited && (mcfrs_console_port == info->line)) { | 
|  | 1227 | /* Do not disable the UART */ ; | 
|  | 1228 | } else | 
|  | 1229 | #endif | 
|  | 1230 | shutdown(info); | 
|  | 1231 | if (tty->driver->flush_buffer) | 
|  | 1232 | tty->driver->flush_buffer(tty); | 
|  | 1233 | tty_ldisc_flush(tty); | 
|  | 1234 |  | 
|  | 1235 | tty->closing = 0; | 
|  | 1236 | info->event = 0; | 
|  | 1237 | info->tty = 0; | 
|  | 1238 | #if 0 | 
|  | 1239 | if (tty->ldisc.num != ldiscs[N_TTY].num) { | 
|  | 1240 | if (tty->ldisc.close) | 
|  | 1241 | (tty->ldisc.close)(tty); | 
|  | 1242 | tty->ldisc = ldiscs[N_TTY]; | 
|  | 1243 | tty->termios->c_line = N_TTY; | 
|  | 1244 | if (tty->ldisc.open) | 
|  | 1245 | (tty->ldisc.open)(tty); | 
|  | 1246 | } | 
|  | 1247 | #endif | 
|  | 1248 | if (info->blocked_open) { | 
|  | 1249 | if (info->close_delay) { | 
|  | 1250 | msleep_interruptible(jiffies_to_msecs(info->close_delay)); | 
|  | 1251 | } | 
|  | 1252 | wake_up_interruptible(&info->open_wait); | 
|  | 1253 | } | 
|  | 1254 | info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING); | 
|  | 1255 | wake_up_interruptible(&info->close_wait); | 
|  | 1256 | local_irq_restore(flags); | 
|  | 1257 | } | 
|  | 1258 |  | 
|  | 1259 | /* | 
|  | 1260 | * mcfrs_wait_until_sent() --- wait until the transmitter is empty | 
|  | 1261 | */ | 
|  | 1262 | static void | 
|  | 1263 | mcfrs_wait_until_sent(struct tty_struct *tty, int timeout) | 
|  | 1264 | { | 
|  | 1265 | #ifdef	CONFIG_M5272 | 
|  | 1266 | #define	MCF5272_FIFO_SIZE	25		/* fifo size + shift reg */ | 
|  | 1267 |  | 
|  | 1268 | struct mcf_serial * info = (struct mcf_serial *)tty->driver_data; | 
|  | 1269 | volatile unsigned char *uartp; | 
|  | 1270 | unsigned long orig_jiffies, fifo_time, char_time, fifo_cnt; | 
|  | 1271 |  | 
|  | 1272 | if (serial_paranoia_check(info, tty->name, "mcfrs_wait_until_sent")) | 
|  | 1273 | return; | 
|  | 1274 |  | 
|  | 1275 | orig_jiffies = jiffies; | 
|  | 1276 |  | 
|  | 1277 | /* | 
|  | 1278 | * Set the check interval to be 1/5 of the approximate time | 
|  | 1279 | * to send the entire fifo, and make it at least 1.  The check | 
|  | 1280 | * interval should also be less than the timeout. | 
|  | 1281 | * | 
|  | 1282 | * Note: we have to use pretty tight timings here to satisfy | 
|  | 1283 | * the NIST-PCTS. | 
|  | 1284 | */ | 
|  | 1285 | fifo_time = (MCF5272_FIFO_SIZE * HZ * 10) / info->baud; | 
|  | 1286 | char_time = fifo_time / 5; | 
|  | 1287 | if (char_time == 0) | 
|  | 1288 | char_time = 1; | 
|  | 1289 | if (timeout && timeout < char_time) | 
|  | 1290 | char_time = timeout; | 
|  | 1291 |  | 
|  | 1292 | /* | 
|  | 1293 | * Clamp the timeout period at 2 * the time to empty the | 
|  | 1294 | * fifo.  Just to be safe, set the minimum at .5 seconds. | 
|  | 1295 | */ | 
|  | 1296 | fifo_time *= 2; | 
|  | 1297 | if (fifo_time < (HZ/2)) | 
|  | 1298 | fifo_time = HZ/2; | 
|  | 1299 | if (!timeout || timeout > fifo_time) | 
|  | 1300 | timeout = fifo_time; | 
|  | 1301 |  | 
|  | 1302 | /* | 
|  | 1303 | * Account for the number of bytes in the UART | 
|  | 1304 | * transmitter FIFO plus any byte being shifted out. | 
|  | 1305 | */ | 
|  | 1306 | uartp = (volatile unsigned char *) info->addr; | 
|  | 1307 | for (;;) { | 
|  | 1308 | fifo_cnt = (uartp[MCFUART_UTF] & MCFUART_UTF_TXB); | 
|  | 1309 | if ((uartp[MCFUART_USR] & (MCFUART_USR_TXREADY| | 
|  | 1310 | MCFUART_USR_TXEMPTY)) == | 
|  | 1311 | MCFUART_USR_TXREADY) | 
|  | 1312 | fifo_cnt++; | 
|  | 1313 | if (fifo_cnt == 0) | 
|  | 1314 | break; | 
|  | 1315 | msleep_interruptible(jiffies_to_msecs(char_time)); | 
|  | 1316 | if (signal_pending(current)) | 
|  | 1317 | break; | 
|  | 1318 | if (timeout && time_after(jiffies, orig_jiffies + timeout)) | 
|  | 1319 | break; | 
|  | 1320 | } | 
|  | 1321 | #else | 
|  | 1322 | /* | 
|  | 1323 | * For the other coldfire models, assume all data has been sent | 
|  | 1324 | */ | 
|  | 1325 | #endif | 
|  | 1326 | } | 
|  | 1327 |  | 
|  | 1328 | /* | 
|  | 1329 | * mcfrs_hangup() --- called by tty_hangup() when a hangup is signaled. | 
|  | 1330 | */ | 
|  | 1331 | void mcfrs_hangup(struct tty_struct *tty) | 
|  | 1332 | { | 
|  | 1333 | struct mcf_serial * info = (struct mcf_serial *)tty->driver_data; | 
|  | 1334 |  | 
|  | 1335 | if (serial_paranoia_check(info, tty->name, "mcfrs_hangup")) | 
|  | 1336 | return; | 
|  | 1337 |  | 
|  | 1338 | mcfrs_flush_buffer(tty); | 
|  | 1339 | shutdown(info); | 
|  | 1340 | info->event = 0; | 
|  | 1341 | info->count = 0; | 
|  | 1342 | info->flags &= ~ASYNC_NORMAL_ACTIVE; | 
|  | 1343 | info->tty = 0; | 
|  | 1344 | wake_up_interruptible(&info->open_wait); | 
|  | 1345 | } | 
|  | 1346 |  | 
|  | 1347 | /* | 
|  | 1348 | * ------------------------------------------------------------ | 
|  | 1349 | * mcfrs_open() and friends | 
|  | 1350 | * ------------------------------------------------------------ | 
|  | 1351 | */ | 
|  | 1352 | static int block_til_ready(struct tty_struct *tty, struct file * filp, | 
|  | 1353 | struct mcf_serial *info) | 
|  | 1354 | { | 
|  | 1355 | DECLARE_WAITQUEUE(wait, current); | 
|  | 1356 | int	retval; | 
|  | 1357 | int	do_clocal = 0; | 
|  | 1358 |  | 
|  | 1359 | /* | 
|  | 1360 | * If the device is in the middle of being closed, then block | 
|  | 1361 | * until it's done, and then try again. | 
|  | 1362 | */ | 
|  | 1363 | if (info->flags & ASYNC_CLOSING) { | 
|  | 1364 | interruptible_sleep_on(&info->close_wait); | 
|  | 1365 | #ifdef SERIAL_DO_RESTART | 
|  | 1366 | if (info->flags & ASYNC_HUP_NOTIFY) | 
|  | 1367 | return -EAGAIN; | 
|  | 1368 | else | 
|  | 1369 | return -ERESTARTSYS; | 
|  | 1370 | #else | 
|  | 1371 | return -EAGAIN; | 
|  | 1372 | #endif | 
|  | 1373 | } | 
|  | 1374 |  | 
|  | 1375 | /* | 
|  | 1376 | * If non-blocking mode is set, or the port is not enabled, | 
|  | 1377 | * then make the check up front and then exit. | 
|  | 1378 | */ | 
|  | 1379 | if ((filp->f_flags & O_NONBLOCK) || | 
|  | 1380 | (tty->flags & (1 << TTY_IO_ERROR))) { | 
|  | 1381 | info->flags |= ASYNC_NORMAL_ACTIVE; | 
|  | 1382 | return 0; | 
|  | 1383 | } | 
|  | 1384 |  | 
|  | 1385 | if (tty->termios->c_cflag & CLOCAL) | 
|  | 1386 | do_clocal = 1; | 
|  | 1387 |  | 
|  | 1388 | /* | 
|  | 1389 | * Block waiting for the carrier detect and the line to become | 
|  | 1390 | * free (i.e., not in use by the callout).  While we are in | 
|  | 1391 | * this loop, info->count is dropped by one, so that | 
|  | 1392 | * mcfrs_close() knows when to free things.  We restore it upon | 
|  | 1393 | * exit, either normal or abnormal. | 
|  | 1394 | */ | 
|  | 1395 | retval = 0; | 
|  | 1396 | add_wait_queue(&info->open_wait, &wait); | 
|  | 1397 | #ifdef SERIAL_DEBUG_OPEN | 
|  | 1398 | printk("block_til_ready before block: ttyS%d, count = %d\n", | 
|  | 1399 | info->line, info->count); | 
|  | 1400 | #endif | 
|  | 1401 | info->count--; | 
|  | 1402 | info->blocked_open++; | 
|  | 1403 | while (1) { | 
|  | 1404 | local_irq_disable(); | 
|  | 1405 | mcfrs_setsignals(info, 1, 1); | 
|  | 1406 | local_irq_enable(); | 
|  | 1407 | current->state = TASK_INTERRUPTIBLE; | 
|  | 1408 | if (tty_hung_up_p(filp) || | 
|  | 1409 | !(info->flags & ASYNC_INITIALIZED)) { | 
|  | 1410 | #ifdef SERIAL_DO_RESTART | 
|  | 1411 | if (info->flags & ASYNC_HUP_NOTIFY) | 
|  | 1412 | retval = -EAGAIN; | 
|  | 1413 | else | 
|  | 1414 | retval = -ERESTARTSYS; | 
|  | 1415 | #else | 
|  | 1416 | retval = -EAGAIN; | 
|  | 1417 | #endif | 
|  | 1418 | break; | 
|  | 1419 | } | 
|  | 1420 | if (!(info->flags & ASYNC_CLOSING) && | 
|  | 1421 | (do_clocal || (mcfrs_getsignals(info) & TIOCM_CD))) | 
|  | 1422 | break; | 
|  | 1423 | if (signal_pending(current)) { | 
|  | 1424 | retval = -ERESTARTSYS; | 
|  | 1425 | break; | 
|  | 1426 | } | 
|  | 1427 | #ifdef SERIAL_DEBUG_OPEN | 
|  | 1428 | printk("block_til_ready blocking: ttyS%d, count = %d\n", | 
|  | 1429 | info->line, info->count); | 
|  | 1430 | #endif | 
|  | 1431 | schedule(); | 
|  | 1432 | } | 
|  | 1433 | current->state = TASK_RUNNING; | 
|  | 1434 | remove_wait_queue(&info->open_wait, &wait); | 
|  | 1435 | if (!tty_hung_up_p(filp)) | 
|  | 1436 | info->count++; | 
|  | 1437 | info->blocked_open--; | 
|  | 1438 | #ifdef SERIAL_DEBUG_OPEN | 
|  | 1439 | printk("block_til_ready after blocking: ttyS%d, count = %d\n", | 
|  | 1440 | info->line, info->count); | 
|  | 1441 | #endif | 
|  | 1442 | if (retval) | 
|  | 1443 | return retval; | 
|  | 1444 | info->flags |= ASYNC_NORMAL_ACTIVE; | 
|  | 1445 | return 0; | 
|  | 1446 | } | 
|  | 1447 |  | 
|  | 1448 | /* | 
|  | 1449 | * This routine is called whenever a serial port is opened. It | 
|  | 1450 | * enables interrupts for a serial port, linking in its structure into | 
|  | 1451 | * the IRQ chain.   It also performs the serial-specific | 
|  | 1452 | * initialization for the tty structure. | 
|  | 1453 | */ | 
|  | 1454 | int mcfrs_open(struct tty_struct *tty, struct file * filp) | 
|  | 1455 | { | 
|  | 1456 | struct mcf_serial	*info; | 
|  | 1457 | int 			retval, line; | 
|  | 1458 |  | 
|  | 1459 | line = tty->index; | 
|  | 1460 | if ((line < 0) || (line >= NR_PORTS)) | 
|  | 1461 | return -ENODEV; | 
|  | 1462 | info = mcfrs_table + line; | 
|  | 1463 | if (serial_paranoia_check(info, tty->name, "mcfrs_open")) | 
|  | 1464 | return -ENODEV; | 
|  | 1465 | #ifdef SERIAL_DEBUG_OPEN | 
|  | 1466 | printk("mcfrs_open %s, count = %d\n", tty->name, info->count); | 
|  | 1467 | #endif | 
|  | 1468 | info->count++; | 
|  | 1469 | tty->driver_data = info; | 
|  | 1470 | info->tty = tty; | 
|  | 1471 |  | 
|  | 1472 | /* | 
|  | 1473 | * Start up serial port | 
|  | 1474 | */ | 
|  | 1475 | retval = startup(info); | 
|  | 1476 | if (retval) | 
|  | 1477 | return retval; | 
|  | 1478 |  | 
|  | 1479 | retval = block_til_ready(tty, filp, info); | 
|  | 1480 | if (retval) { | 
|  | 1481 | #ifdef SERIAL_DEBUG_OPEN | 
|  | 1482 | printk("mcfrs_open returning after block_til_ready with %d\n", | 
|  | 1483 | retval); | 
|  | 1484 | #endif | 
|  | 1485 | return retval; | 
|  | 1486 | } | 
|  | 1487 |  | 
|  | 1488 | #ifdef SERIAL_DEBUG_OPEN | 
|  | 1489 | printk("mcfrs_open %s successful...\n", tty->name); | 
|  | 1490 | #endif | 
|  | 1491 | return 0; | 
|  | 1492 | } | 
|  | 1493 |  | 
|  | 1494 | /* | 
|  | 1495 | *	Based on the line number set up the internal interrupt stuff. | 
|  | 1496 | */ | 
|  | 1497 | static void mcfrs_irqinit(struct mcf_serial *info) | 
|  | 1498 | { | 
|  | 1499 | #if defined(CONFIG_M5272) | 
|  | 1500 | volatile unsigned long	*icrp; | 
|  | 1501 | volatile unsigned long	*portp; | 
|  | 1502 | volatile unsigned char	*uartp; | 
|  | 1503 |  | 
|  | 1504 | uartp = info->addr; | 
|  | 1505 | icrp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_ICR2); | 
|  | 1506 |  | 
|  | 1507 | switch (info->line) { | 
|  | 1508 | case 0: | 
|  | 1509 | *icrp = 0xe0000000; | 
|  | 1510 | break; | 
|  | 1511 | case 1: | 
|  | 1512 | *icrp = 0x0e000000; | 
|  | 1513 | break; | 
|  | 1514 | default: | 
|  | 1515 | printk("MCFRS: don't know how to handle UART %d interrupt?\n", | 
|  | 1516 | info->line); | 
|  | 1517 | return; | 
|  | 1518 | } | 
|  | 1519 |  | 
|  | 1520 | /* Enable the output lines for the serial ports */ | 
|  | 1521 | portp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_PBCNT); | 
|  | 1522 | *portp = (*portp & ~0x000000ff) | 0x00000055; | 
|  | 1523 | portp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_PDCNT); | 
|  | 1524 | *portp = (*portp & ~0x000003fc) | 0x000002a8; | 
| Greg Ungerer | b0433b9 | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 1525 | #elif defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1526 | volatile unsigned char *icrp, *uartp; | 
|  | 1527 | volatile unsigned long *imrp; | 
|  | 1528 |  | 
|  | 1529 | uartp = info->addr; | 
|  | 1530 |  | 
|  | 1531 | icrp = (volatile unsigned char *) (MCF_MBAR + MCFICM_INTC0 + | 
|  | 1532 | MCFINTC_ICR0 + MCFINT_UART0 + info->line); | 
| Greg Ungerer | 082f2c1 | 2006-01-10 16:59:04 +1000 | [diff] [blame] | 1533 | *icrp = 0x30 + info->line; /* level 6, line based priority */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1534 |  | 
|  | 1535 | imrp = (volatile unsigned long *) (MCF_MBAR + MCFICM_INTC0 + | 
|  | 1536 | MCFINTC_IMRL); | 
|  | 1537 | *imrp &= ~((1 << (info->irq - MCFINT_VECBASE)) | 1); | 
| Greg Ungerer | a8b8d57 | 2006-12-06 11:49:34 +1000 | [diff] [blame] | 1538 | #if defined(CONFIG_M527x) | 
|  | 1539 | { | 
|  | 1540 | /* | 
|  | 1541 | * External Pin Mask Setting & Enable External Pin for Interface | 
|  | 1542 | * mrcbis@aliceposta.it | 
|  | 1543 | */ | 
|  | 1544 | unsigned short *serpin_enable_mask; | 
|  | 1545 | serpin_enable_mask = (MCF_IPSBAR + MCF_GPIO_PAR_UART); | 
|  | 1546 | if (info->line == 0) | 
|  | 1547 | *serpin_enable_mask |= UART0_ENABLE_MASK; | 
|  | 1548 | else if (info->line == 1) | 
|  | 1549 | *serpin_enable_mask |= UART1_ENABLE_MASK; | 
|  | 1550 | else if (info->line == 2) | 
|  | 1551 | *serpin_enable_mask |= UART2_ENABLE_MASK; | 
|  | 1552 | } | 
|  | 1553 | #endif | 
| Greg Ungerer | 7f04d62 | 2005-11-07 14:09:50 +1000 | [diff] [blame] | 1554 | #elif defined(CONFIG_M520x) | 
|  | 1555 | volatile unsigned char *icrp, *uartp; | 
|  | 1556 | volatile unsigned long *imrp; | 
|  | 1557 |  | 
|  | 1558 | uartp = info->addr; | 
|  | 1559 |  | 
|  | 1560 | icrp = (volatile unsigned char *) (MCF_MBAR + MCFICM_INTC0 + | 
|  | 1561 | MCFINTC_ICR0 + MCFINT_UART0 + info->line); | 
|  | 1562 | *icrp = 0x03; | 
|  | 1563 |  | 
|  | 1564 | imrp = (volatile unsigned long *) (MCF_MBAR + MCFICM_INTC0 + | 
|  | 1565 | MCFINTC_IMRL); | 
|  | 1566 | *imrp &= ~((1 << (info->irq - MCFINT_VECBASE)) | 1); | 
|  | 1567 | if (info->line < 2) { | 
|  | 1568 | unsigned short *uart_par; | 
|  | 1569 | uart_par = (unsigned short *)(MCF_IPSBAR + MCF_GPIO_PAR_UART); | 
|  | 1570 | if (info->line == 0) | 
|  | 1571 | *uart_par |=  MCF_GPIO_PAR_UART_PAR_UTXD0 | 
|  | 1572 | | MCF_GPIO_PAR_UART_PAR_URXD0; | 
|  | 1573 | else if (info->line == 1) | 
|  | 1574 | *uart_par |=  MCF_GPIO_PAR_UART_PAR_UTXD1 | 
|  | 1575 | | MCF_GPIO_PAR_UART_PAR_URXD1; | 
|  | 1576 | } else if (info->line == 2) { | 
|  | 1577 | unsigned char *feci2c_par; | 
|  | 1578 | feci2c_par = (unsigned char *)(MCF_IPSBAR +  MCF_GPIO_PAR_FECI2C); | 
|  | 1579 | *feci2c_par &= ~0x0F; | 
|  | 1580 | *feci2c_par |=  MCF_GPIO_PAR_FECI2C_PAR_SCL_UTXD2 | 
|  | 1581 | | MCF_GPIO_PAR_FECI2C_PAR_SDA_URXD2; | 
|  | 1582 | } | 
| Greg Ungerer | 76aa698 | 2006-06-26 10:33:10 +1000 | [diff] [blame] | 1583 | #elif defined(CONFIG_M532x) | 
|  | 1584 | volatile unsigned char *uartp; | 
|  | 1585 | uartp = info->addr; | 
|  | 1586 | switch (info->line) { | 
|  | 1587 | case 0: | 
|  | 1588 | MCF_INTC0_ICR26 = 0x3; | 
|  | 1589 | MCF_INTC0_CIMR = 26; | 
|  | 1590 | /* GPIO initialization */ | 
|  | 1591 | MCF_GPIO_PAR_UART |= 0x000F; | 
|  | 1592 | break; | 
|  | 1593 | case 1: | 
|  | 1594 | MCF_INTC0_ICR27 = 0x3; | 
|  | 1595 | MCF_INTC0_CIMR = 27; | 
|  | 1596 | /* GPIO initialization */ | 
|  | 1597 | MCF_GPIO_PAR_UART |= 0x0FF0; | 
|  | 1598 | break; | 
|  | 1599 | case 2: | 
|  | 1600 | MCF_INTC0_ICR28 = 0x3; | 
|  | 1601 | MCF_INTC0_CIMR = 28; | 
|  | 1602 | /* GPIOs also must be initalized, depends on board */ | 
|  | 1603 | break; | 
|  | 1604 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1605 | #else | 
|  | 1606 | volatile unsigned char	*icrp, *uartp; | 
|  | 1607 |  | 
|  | 1608 | switch (info->line) { | 
|  | 1609 | case 0: | 
|  | 1610 | icrp = (volatile unsigned char *) (MCF_MBAR + MCFSIM_UART1ICR); | 
|  | 1611 | *icrp = /*MCFSIM_ICR_AUTOVEC |*/ MCFSIM_ICR_LEVEL6 | | 
|  | 1612 | MCFSIM_ICR_PRI1; | 
|  | 1613 | mcf_setimr(mcf_getimr() & ~MCFSIM_IMR_UART1); | 
|  | 1614 | break; | 
|  | 1615 | case 1: | 
|  | 1616 | icrp = (volatile unsigned char *) (MCF_MBAR + MCFSIM_UART2ICR); | 
|  | 1617 | *icrp = /*MCFSIM_ICR_AUTOVEC |*/ MCFSIM_ICR_LEVEL6 | | 
|  | 1618 | MCFSIM_ICR_PRI2; | 
|  | 1619 | mcf_setimr(mcf_getimr() & ~MCFSIM_IMR_UART2); | 
|  | 1620 | break; | 
|  | 1621 | default: | 
|  | 1622 | printk("MCFRS: don't know how to handle UART %d interrupt?\n", | 
|  | 1623 | info->line); | 
|  | 1624 | return; | 
|  | 1625 | } | 
|  | 1626 |  | 
|  | 1627 | uartp = info->addr; | 
|  | 1628 | uartp[MCFUART_UIVR] = info->irq; | 
|  | 1629 | #endif | 
|  | 1630 |  | 
|  | 1631 | /* Clear mask, so no surprise interrupts. */ | 
|  | 1632 | uartp[MCFUART_UIMR] = 0; | 
|  | 1633 |  | 
| Thomas Gleixner | 40663cc | 2006-07-01 19:29:43 -0700 | [diff] [blame] | 1634 | if (request_irq(info->irq, mcfrs_interrupt, IRQF_DISABLED, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1635 | "ColdFire UART", NULL)) { | 
|  | 1636 | printk("MCFRS: Unable to attach ColdFire UART %d interrupt " | 
|  | 1637 | "vector=%d\n", info->line, info->irq); | 
|  | 1638 | } | 
|  | 1639 |  | 
|  | 1640 | return; | 
|  | 1641 | } | 
|  | 1642 |  | 
|  | 1643 |  | 
|  | 1644 | char *mcfrs_drivername = "ColdFire internal UART serial driver version 1.00\n"; | 
|  | 1645 |  | 
|  | 1646 |  | 
|  | 1647 | /* | 
|  | 1648 | * Serial stats reporting... | 
|  | 1649 | */ | 
|  | 1650 | int mcfrs_readproc(char *page, char **start, off_t off, int count, | 
|  | 1651 | int *eof, void *data) | 
|  | 1652 | { | 
|  | 1653 | struct mcf_serial	*info; | 
|  | 1654 | char			str[20]; | 
|  | 1655 | int			len, sigs, i; | 
|  | 1656 |  | 
|  | 1657 | len = sprintf(page, mcfrs_drivername); | 
|  | 1658 | for (i = 0; (i < NR_PORTS); i++) { | 
|  | 1659 | info = &mcfrs_table[i]; | 
|  | 1660 | len += sprintf((page + len), "%d: port:%x irq=%d baud:%d ", | 
|  | 1661 | i, (unsigned int) info->addr, info->irq, info->baud); | 
|  | 1662 | if (info->stats.rx || info->stats.tx) | 
|  | 1663 | len += sprintf((page + len), "tx:%d rx:%d ", | 
|  | 1664 | info->stats.tx, info->stats.rx); | 
|  | 1665 | if (info->stats.rxframing) | 
|  | 1666 | len += sprintf((page + len), "fe:%d ", | 
|  | 1667 | info->stats.rxframing); | 
|  | 1668 | if (info->stats.rxparity) | 
|  | 1669 | len += sprintf((page + len), "pe:%d ", | 
|  | 1670 | info->stats.rxparity); | 
|  | 1671 | if (info->stats.rxbreak) | 
|  | 1672 | len += sprintf((page + len), "brk:%d ", | 
|  | 1673 | info->stats.rxbreak); | 
|  | 1674 | if (info->stats.rxoverrun) | 
|  | 1675 | len += sprintf((page + len), "oe:%d ", | 
|  | 1676 | info->stats.rxoverrun); | 
|  | 1677 |  | 
|  | 1678 | str[0] = str[1] = 0; | 
|  | 1679 | if ((sigs = mcfrs_getsignals(info))) { | 
|  | 1680 | if (sigs & TIOCM_RTS) | 
|  | 1681 | strcat(str, "|RTS"); | 
|  | 1682 | if (sigs & TIOCM_CTS) | 
|  | 1683 | strcat(str, "|CTS"); | 
|  | 1684 | if (sigs & TIOCM_DTR) | 
|  | 1685 | strcat(str, "|DTR"); | 
|  | 1686 | if (sigs & TIOCM_CD) | 
|  | 1687 | strcat(str, "|CD"); | 
|  | 1688 | } | 
|  | 1689 |  | 
|  | 1690 | len += sprintf((page + len), "%s\n", &str[1]); | 
|  | 1691 | } | 
|  | 1692 |  | 
|  | 1693 | return(len); | 
|  | 1694 | } | 
|  | 1695 |  | 
|  | 1696 |  | 
|  | 1697 | /* Finally, routines used to initialize the serial driver. */ | 
|  | 1698 |  | 
|  | 1699 | static void show_serial_version(void) | 
|  | 1700 | { | 
|  | 1701 | printk(mcfrs_drivername); | 
|  | 1702 | } | 
|  | 1703 |  | 
| Jeff Dike | b68e31d | 2006-10-02 02:17:18 -0700 | [diff] [blame] | 1704 | static const struct tty_operations mcfrs_ops = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1705 | .open = mcfrs_open, | 
|  | 1706 | .close = mcfrs_close, | 
|  | 1707 | .write = mcfrs_write, | 
|  | 1708 | .flush_chars = mcfrs_flush_chars, | 
|  | 1709 | .write_room = mcfrs_write_room, | 
|  | 1710 | .chars_in_buffer = mcfrs_chars_in_buffer, | 
|  | 1711 | .flush_buffer = mcfrs_flush_buffer, | 
|  | 1712 | .ioctl = mcfrs_ioctl, | 
|  | 1713 | .throttle = mcfrs_throttle, | 
|  | 1714 | .unthrottle = mcfrs_unthrottle, | 
|  | 1715 | .set_termios = mcfrs_set_termios, | 
|  | 1716 | .stop = mcfrs_stop, | 
|  | 1717 | .start = mcfrs_start, | 
|  | 1718 | .hangup = mcfrs_hangup, | 
|  | 1719 | .read_proc = mcfrs_readproc, | 
|  | 1720 | .wait_until_sent = mcfrs_wait_until_sent, | 
|  | 1721 | .tiocmget = mcfrs_tiocmget, | 
|  | 1722 | .tiocmset = mcfrs_tiocmset, | 
|  | 1723 | }; | 
|  | 1724 |  | 
|  | 1725 | /* mcfrs_init inits the driver */ | 
|  | 1726 | static int __init | 
|  | 1727 | mcfrs_init(void) | 
|  | 1728 | { | 
|  | 1729 | struct mcf_serial	*info; | 
|  | 1730 | unsigned long		flags; | 
|  | 1731 | int			i; | 
|  | 1732 |  | 
|  | 1733 | /* Setup base handler, and timer table. */ | 
|  | 1734 | #ifdef MCFPP_DCD0 | 
|  | 1735 | init_timer(&mcfrs_timer_struct); | 
|  | 1736 | mcfrs_timer_struct.function = mcfrs_timer; | 
|  | 1737 | mcfrs_timer_struct.data = 0; | 
|  | 1738 | mcfrs_timer_struct.expires = jiffies + HZ/25; | 
|  | 1739 | add_timer(&mcfrs_timer_struct); | 
|  | 1740 | mcfrs_ppstatus = mcf_getppdata() & (MCFPP_DCD0 | MCFPP_DCD1); | 
|  | 1741 | #endif | 
|  | 1742 | mcfrs_serial_driver = alloc_tty_driver(NR_PORTS); | 
|  | 1743 | if (!mcfrs_serial_driver) | 
|  | 1744 | return -ENOMEM; | 
|  | 1745 |  | 
|  | 1746 | show_serial_version(); | 
|  | 1747 |  | 
|  | 1748 | /* Initialize the tty_driver structure */ | 
|  | 1749 | mcfrs_serial_driver->owner = THIS_MODULE; | 
|  | 1750 | mcfrs_serial_driver->name = "ttyS"; | 
| Greg Ungerer | a8b8d57 | 2006-12-06 11:49:34 +1000 | [diff] [blame] | 1751 | mcfrs_serial_driver->driver_name = "mcfserial"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1752 | mcfrs_serial_driver->major = TTY_MAJOR; | 
|  | 1753 | mcfrs_serial_driver->minor_start = 64; | 
|  | 1754 | mcfrs_serial_driver->type = TTY_DRIVER_TYPE_SERIAL; | 
|  | 1755 | mcfrs_serial_driver->subtype = SERIAL_TYPE_NORMAL; | 
|  | 1756 | mcfrs_serial_driver->init_termios = tty_std_termios; | 
|  | 1757 |  | 
|  | 1758 | mcfrs_serial_driver->init_termios.c_cflag = | 
|  | 1759 | mcfrs_console_cbaud | CS8 | CREAD | HUPCL | CLOCAL; | 
|  | 1760 | mcfrs_serial_driver->flags = TTY_DRIVER_REAL_RAW; | 
|  | 1761 |  | 
|  | 1762 | tty_set_operations(mcfrs_serial_driver, &mcfrs_ops); | 
|  | 1763 |  | 
|  | 1764 | if (tty_register_driver(mcfrs_serial_driver)) { | 
|  | 1765 | printk("MCFRS: Couldn't register serial driver\n"); | 
|  | 1766 | put_tty_driver(mcfrs_serial_driver); | 
|  | 1767 | return(-EBUSY); | 
|  | 1768 | } | 
|  | 1769 |  | 
|  | 1770 | local_irq_save(flags); | 
|  | 1771 |  | 
|  | 1772 | /* | 
|  | 1773 | *	Configure all the attached serial ports. | 
|  | 1774 | */ | 
|  | 1775 | for (i = 0, info = mcfrs_table; (i < NR_PORTS); i++, info++) { | 
|  | 1776 | info->magic = SERIAL_MAGIC; | 
|  | 1777 | info->line = i; | 
|  | 1778 | info->tty = 0; | 
|  | 1779 | info->custom_divisor = 16; | 
|  | 1780 | info->close_delay = 50; | 
|  | 1781 | info->closing_wait = 3000; | 
|  | 1782 | info->x_char = 0; | 
|  | 1783 | info->event = 0; | 
|  | 1784 | info->count = 0; | 
|  | 1785 | info->blocked_open = 0; | 
|  | 1786 | INIT_WORK(&info->tqueue, mcfrs_offintr, info); | 
|  | 1787 | INIT_WORK(&info->tqueue_hangup, do_serial_hangup, info); | 
|  | 1788 | init_waitqueue_head(&info->open_wait); | 
|  | 1789 | init_waitqueue_head(&info->close_wait); | 
|  | 1790 |  | 
|  | 1791 | info->imr = 0; | 
|  | 1792 | mcfrs_setsignals(info, 0, 0); | 
|  | 1793 | mcfrs_irqinit(info); | 
|  | 1794 |  | 
|  | 1795 | printk("ttyS%d at 0x%04x (irq = %d)", info->line, | 
|  | 1796 | (unsigned int) info->addr, info->irq); | 
|  | 1797 | printk(" is a builtin ColdFire UART\n"); | 
|  | 1798 | } | 
|  | 1799 |  | 
|  | 1800 | local_irq_restore(flags); | 
|  | 1801 | return 0; | 
|  | 1802 | } | 
|  | 1803 |  | 
|  | 1804 | module_init(mcfrs_init); | 
|  | 1805 |  | 
|  | 1806 | /****************************************************************************/ | 
|  | 1807 | /*                          Serial Console                                  */ | 
|  | 1808 | /****************************************************************************/ | 
|  | 1809 |  | 
|  | 1810 | /* | 
|  | 1811 | *	Quick and dirty UART initialization, for console output. | 
|  | 1812 | */ | 
|  | 1813 |  | 
|  | 1814 | void mcfrs_init_console(void) | 
|  | 1815 | { | 
|  | 1816 | volatile unsigned char	*uartp; | 
|  | 1817 | unsigned int		clk; | 
|  | 1818 |  | 
|  | 1819 | /* | 
|  | 1820 | *	Reset UART, get it into known state... | 
|  | 1821 | */ | 
|  | 1822 | uartp = (volatile unsigned char *) (MCF_MBAR + | 
|  | 1823 | (mcfrs_console_port ? MCFUART_BASE2 : MCFUART_BASE1)); | 
|  | 1824 |  | 
|  | 1825 | uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETRX;  /* reset RX */ | 
|  | 1826 | uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETTX;  /* reset TX */ | 
|  | 1827 | uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETMRPTR;  /* reset MR pointer */ | 
|  | 1828 |  | 
|  | 1829 | /* | 
|  | 1830 | * Set port for defined baud , 8 data bits, 1 stop bit, no parity. | 
|  | 1831 | */ | 
|  | 1832 | uartp[MCFUART_UMR] = MCFUART_MR1_PARITYNONE | MCFUART_MR1_CS8; | 
|  | 1833 | uartp[MCFUART_UMR] = MCFUART_MR2_STOP1; | 
|  | 1834 |  | 
| Greg Ungerer | a8b8d57 | 2006-12-06 11:49:34 +1000 | [diff] [blame] | 1835 | #ifdef	CONFIG_M5272 | 
|  | 1836 | { | 
|  | 1837 | /* | 
|  | 1838 | * For the MCF5272, also compute the baudrate fraction. | 
|  | 1839 | */ | 
|  | 1840 | int fraction = MCF_BUSCLK - (clk * 32 * mcfrs_console_baud); | 
|  | 1841 | fraction *= 16; | 
|  | 1842 | fraction /= (32 * mcfrs_console_baud); | 
|  | 1843 | uartp[MCFUART_UFPD] = (fraction & 0xf);		/* set fraction */ | 
|  | 1844 | clk = (MCF_BUSCLK / mcfrs_console_baud) / 32; | 
|  | 1845 | } | 
|  | 1846 | #else | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1847 | clk = ((MCF_BUSCLK / mcfrs_console_baud) + 16) / 32; /* set baud */ | 
| Greg Ungerer | a8b8d57 | 2006-12-06 11:49:34 +1000 | [diff] [blame] | 1848 | #endif | 
|  | 1849 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1850 | uartp[MCFUART_UBG1] = (clk & 0xff00) >> 8;  /* set msb baud */ | 
|  | 1851 | uartp[MCFUART_UBG2] = (clk & 0xff);  /* set lsb baud */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1852 | uartp[MCFUART_UCSR] = MCFUART_UCSR_RXCLKTIMER | MCFUART_UCSR_TXCLKTIMER; | 
|  | 1853 | uartp[MCFUART_UCR] = MCFUART_UCR_RXENABLE | MCFUART_UCR_TXENABLE; | 
|  | 1854 |  | 
|  | 1855 | mcfrs_console_inited++; | 
|  | 1856 | return; | 
|  | 1857 | } | 
|  | 1858 |  | 
|  | 1859 |  | 
|  | 1860 | /* | 
|  | 1861 | *	Setup for console. Argument comes from the boot command line. | 
|  | 1862 | */ | 
|  | 1863 |  | 
|  | 1864 | int mcfrs_console_setup(struct console *cp, char *arg) | 
|  | 1865 | { | 
|  | 1866 | int		i, n = CONSOLE_BAUD_RATE; | 
|  | 1867 |  | 
|  | 1868 | if (!cp) | 
|  | 1869 | return(-1); | 
|  | 1870 |  | 
|  | 1871 | if (!strncmp(cp->name, "ttyS", 4)) | 
|  | 1872 | mcfrs_console_port = cp->index; | 
|  | 1873 | else if (!strncmp(cp->name, "cua", 3)) | 
|  | 1874 | mcfrs_console_port = cp->index; | 
|  | 1875 | else | 
|  | 1876 | return(-1); | 
|  | 1877 |  | 
|  | 1878 | if (arg) | 
|  | 1879 | n = simple_strtoul(arg,NULL,0); | 
|  | 1880 | for (i = 0; i < MCFRS_BAUD_TABLE_SIZE; i++) | 
|  | 1881 | if (mcfrs_baud_table[i] == n) | 
|  | 1882 | break; | 
|  | 1883 | if (i < MCFRS_BAUD_TABLE_SIZE) { | 
|  | 1884 | mcfrs_console_baud = n; | 
|  | 1885 | mcfrs_console_cbaud = 0; | 
|  | 1886 | if (i > 15) { | 
|  | 1887 | mcfrs_console_cbaud |= CBAUDEX; | 
|  | 1888 | i -= 15; | 
|  | 1889 | } | 
|  | 1890 | mcfrs_console_cbaud |= i; | 
|  | 1891 | } | 
|  | 1892 | mcfrs_init_console(); /* make sure baud rate changes */ | 
|  | 1893 | return(0); | 
|  | 1894 | } | 
|  | 1895 |  | 
|  | 1896 |  | 
|  | 1897 | static struct tty_driver *mcfrs_console_device(struct console *c, int *index) | 
|  | 1898 | { | 
|  | 1899 | *index = c->index; | 
|  | 1900 | return mcfrs_serial_driver; | 
|  | 1901 | } | 
|  | 1902 |  | 
|  | 1903 |  | 
|  | 1904 | /* | 
|  | 1905 | *	Output a single character, using UART polled mode. | 
|  | 1906 | *	This is used for console output. | 
|  | 1907 | */ | 
|  | 1908 |  | 
|  | 1909 | void mcfrs_put_char(char ch) | 
|  | 1910 | { | 
|  | 1911 | volatile unsigned char	*uartp; | 
|  | 1912 | unsigned long		flags; | 
|  | 1913 | int			i; | 
|  | 1914 |  | 
|  | 1915 | uartp = (volatile unsigned char *) (MCF_MBAR + | 
|  | 1916 | (mcfrs_console_port ? MCFUART_BASE2 : MCFUART_BASE1)); | 
|  | 1917 |  | 
|  | 1918 | local_irq_save(flags); | 
|  | 1919 | for (i = 0; (i < 0x10000); i++) { | 
|  | 1920 | if (uartp[MCFUART_USR] & MCFUART_USR_TXREADY) | 
|  | 1921 | break; | 
|  | 1922 | } | 
|  | 1923 | if (i < 0x10000) { | 
|  | 1924 | uartp[MCFUART_UTB] = ch; | 
|  | 1925 | for (i = 0; (i < 0x10000); i++) | 
|  | 1926 | if (uartp[MCFUART_USR] & MCFUART_USR_TXEMPTY) | 
|  | 1927 | break; | 
|  | 1928 | } | 
|  | 1929 | if (i >= 0x10000) | 
|  | 1930 | mcfrs_init_console(); /* try and get it back */ | 
|  | 1931 | local_irq_restore(flags); | 
|  | 1932 |  | 
|  | 1933 | return; | 
|  | 1934 | } | 
|  | 1935 |  | 
|  | 1936 |  | 
|  | 1937 | /* | 
|  | 1938 | * rs_console_write is registered for printk output. | 
|  | 1939 | */ | 
|  | 1940 |  | 
|  | 1941 | void mcfrs_console_write(struct console *cp, const char *p, unsigned len) | 
|  | 1942 | { | 
|  | 1943 | if (!mcfrs_console_inited) | 
|  | 1944 | mcfrs_init_console(); | 
|  | 1945 | while (len-- > 0) { | 
|  | 1946 | if (*p == '\n') | 
|  | 1947 | mcfrs_put_char('\r'); | 
|  | 1948 | mcfrs_put_char(*p++); | 
|  | 1949 | } | 
|  | 1950 | } | 
|  | 1951 |  | 
|  | 1952 | /* | 
|  | 1953 | * declare our consoles | 
|  | 1954 | */ | 
|  | 1955 |  | 
|  | 1956 | struct console mcfrs_console = { | 
|  | 1957 | .name		= "ttyS", | 
|  | 1958 | .write		= mcfrs_console_write, | 
|  | 1959 | .device		= mcfrs_console_device, | 
|  | 1960 | .setup		= mcfrs_console_setup, | 
|  | 1961 | .flags		= CON_PRINTBUFFER, | 
|  | 1962 | .index		= -1, | 
|  | 1963 | }; | 
|  | 1964 |  | 
|  | 1965 | static int __init mcfrs_console_init(void) | 
|  | 1966 | { | 
|  | 1967 | register_console(&mcfrs_console); | 
|  | 1968 | return 0; | 
|  | 1969 | } | 
|  | 1970 |  | 
|  | 1971 | console_initcall(mcfrs_console_init); | 
|  | 1972 |  | 
|  | 1973 | /****************************************************************************/ |