Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /*****************************************************************************/ |
| 2 | |
| 3 | /* |
| 4 | * stallion.c -- stallion multiport serial driver. |
| 5 | * |
| 6 | * Copyright (C) 1996-1999 Stallion Technologies |
| 7 | * Copyright (C) 1994-1996 Greg Ungerer. |
| 8 | * |
| 9 | * This code is loosely based on the Linux serial driver, written by |
| 10 | * Linus Torvalds, Theodore T'so and others. |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License as published by |
| 14 | * the Free Software Foundation; either version 2 of the License, or |
| 15 | * (at your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program; if not, write to the Free Software |
| 24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 25 | */ |
| 26 | |
| 27 | /*****************************************************************************/ |
| 28 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <linux/module.h> |
| 30 | #include <linux/slab.h> |
| 31 | #include <linux/interrupt.h> |
| 32 | #include <linux/tty.h> |
| 33 | #include <linux/tty_flip.h> |
| 34 | #include <linux/serial.h> |
| 35 | #include <linux/cd1400.h> |
| 36 | #include <linux/sc26198.h> |
| 37 | #include <linux/comstats.h> |
| 38 | #include <linux/stallion.h> |
| 39 | #include <linux/ioport.h> |
| 40 | #include <linux/init.h> |
| 41 | #include <linux/smp_lock.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include <linux/device.h> |
| 43 | #include <linux/delay.h> |
Jiri Slaby | 843b568 | 2006-12-08 02:39:12 -0800 | [diff] [blame] | 44 | #include <linux/ctype.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
| 46 | #include <asm/io.h> |
| 47 | #include <asm/uaccess.h> |
| 48 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | #include <linux/pci.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
| 51 | /*****************************************************************************/ |
| 52 | |
| 53 | /* |
| 54 | * Define different board types. Use the standard Stallion "assigned" |
| 55 | * board numbers. Boards supported in this driver are abbreviated as |
| 56 | * EIO = EasyIO and ECH = EasyConnection 8/32. |
| 57 | */ |
| 58 | #define BRD_EASYIO 20 |
| 59 | #define BRD_ECH 21 |
| 60 | #define BRD_ECHMC 22 |
| 61 | #define BRD_ECHPCI 26 |
| 62 | #define BRD_ECH64PCI 27 |
| 63 | #define BRD_EASYIOPCI 28 |
| 64 | |
Jiri Slaby | 843b568 | 2006-12-08 02:39:12 -0800 | [diff] [blame] | 65 | struct stlconf { |
Jiri Slaby | 6b2c945 | 2006-12-08 02:39:15 -0800 | [diff] [blame] | 66 | unsigned int brdtype; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | int ioaddr1; |
| 68 | int ioaddr2; |
| 69 | unsigned long memaddr; |
| 70 | int irq; |
| 71 | int irqtype; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | }; |
| 73 | |
Jiri Slaby | 843b568 | 2006-12-08 02:39:12 -0800 | [diff] [blame] | 74 | static unsigned int stl_nrbrds; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
| 76 | /*****************************************************************************/ |
| 77 | |
| 78 | /* |
| 79 | * Define some important driver characteristics. Device major numbers |
| 80 | * allocated as per Linux Device Registry. |
| 81 | */ |
| 82 | #ifndef STL_SIOMEMMAJOR |
| 83 | #define STL_SIOMEMMAJOR 28 |
| 84 | #endif |
| 85 | #ifndef STL_SERIALMAJOR |
| 86 | #define STL_SERIALMAJOR 24 |
| 87 | #endif |
| 88 | #ifndef STL_CALLOUTMAJOR |
| 89 | #define STL_CALLOUTMAJOR 25 |
| 90 | #endif |
| 91 | |
| 92 | /* |
| 93 | * Set the TX buffer size. Bigger is better, but we don't want |
| 94 | * to chew too much memory with buffers! |
| 95 | */ |
| 96 | #define STL_TXBUFLOW 512 |
| 97 | #define STL_TXBUFSIZE 4096 |
| 98 | |
| 99 | /*****************************************************************************/ |
| 100 | |
| 101 | /* |
| 102 | * Define our local driver identity first. Set up stuff to deal with |
| 103 | * all the local structures required by a serial tty driver. |
| 104 | */ |
| 105 | static char *stl_drvtitle = "Stallion Multiport Serial Driver"; |
| 106 | static char *stl_drvname = "stallion"; |
| 107 | static char *stl_drvversion = "5.6.0"; |
| 108 | |
| 109 | static struct tty_driver *stl_serial; |
| 110 | |
| 111 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | * Define a local default termios struct. All ports will be created |
| 113 | * with this termios initially. Basically all it defines is a raw port |
| 114 | * at 9600, 8 data bits, 1 stop bit. |
| 115 | */ |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 116 | static struct ktermios stl_deftermios = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL), |
| 118 | .c_cc = INIT_C_CC, |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 119 | .c_ispeed = 9600, |
| 120 | .c_ospeed = 9600, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | * Define global place to put buffer overflow characters. |
| 125 | */ |
| 126 | static char stl_unwanted[SC26198_RXFIFOSIZE]; |
| 127 | |
| 128 | /*****************************************************************************/ |
| 129 | |
Jiri Slaby | 79cfe7a | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 130 | static DEFINE_MUTEX(stl_brdslock); |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 131 | static struct stlbrd *stl_brds[STL_MAXBRDS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
Alan Cox | 31f3593 | 2009-01-02 13:45:05 +0000 | [diff] [blame^] | 133 | static const struct tty_port_operations stl_port_ops; |
| 134 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | /* |
| 136 | * Per board state flags. Used with the state field of the board struct. |
| 137 | * Not really much here! |
| 138 | */ |
| 139 | #define BRD_FOUND 0x1 |
Jiri Slaby | fc06b5c | 2006-12-08 02:39:13 -0800 | [diff] [blame] | 140 | #define STL_PROBED 0x2 |
| 141 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | |
| 143 | /* |
| 144 | * Define the port structure istate flags. These set of flags are |
| 145 | * modified at interrupt time - so setting and reseting them needs |
| 146 | * to be atomic. Use the bit clear/setting routines for this. |
| 147 | */ |
| 148 | #define ASYI_TXBUSY 1 |
| 149 | #define ASYI_TXLOW 2 |
Jiri Slaby | ccfea3c | 2008-02-07 00:16:39 -0800 | [diff] [blame] | 150 | #define ASYI_TXFLOWED 3 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
| 152 | /* |
| 153 | * Define an array of board names as printable strings. Handy for |
| 154 | * referencing boards when printing trace and stuff. |
| 155 | */ |
| 156 | static char *stl_brdnames[] = { |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 157 | NULL, |
| 158 | NULL, |
| 159 | NULL, |
| 160 | NULL, |
| 161 | NULL, |
| 162 | NULL, |
| 163 | NULL, |
| 164 | NULL, |
| 165 | NULL, |
| 166 | NULL, |
| 167 | NULL, |
| 168 | NULL, |
| 169 | NULL, |
| 170 | NULL, |
| 171 | NULL, |
| 172 | NULL, |
| 173 | NULL, |
| 174 | NULL, |
| 175 | NULL, |
| 176 | NULL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | "EasyIO", |
| 178 | "EC8/32-AT", |
| 179 | "EC8/32-MC", |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 180 | NULL, |
| 181 | NULL, |
| 182 | NULL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | "EC8/32-PCI", |
| 184 | "EC8/64-PCI", |
| 185 | "EasyIO-PCI", |
| 186 | }; |
| 187 | |
| 188 | /*****************************************************************************/ |
| 189 | |
| 190 | /* |
| 191 | * Define some string labels for arguments passed from the module |
| 192 | * load line. These allow for easy board definitions, and easy |
| 193 | * modification of the io, memory and irq resoucres. |
| 194 | */ |
Jiri Slaby | 6b2c945 | 2006-12-08 02:39:15 -0800 | [diff] [blame] | 195 | static unsigned int stl_nargs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | static char *board0[4]; |
| 197 | static char *board1[4]; |
| 198 | static char *board2[4]; |
| 199 | static char *board3[4]; |
| 200 | |
| 201 | static char **stl_brdsp[] = { |
| 202 | (char **) &board0, |
| 203 | (char **) &board1, |
| 204 | (char **) &board2, |
| 205 | (char **) &board3 |
| 206 | }; |
| 207 | |
| 208 | /* |
| 209 | * Define a set of common board names, and types. This is used to |
| 210 | * parse any module arguments. |
| 211 | */ |
| 212 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 213 | static struct { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | char *name; |
| 215 | int type; |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 216 | } stl_brdstr[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | { "easyio", BRD_EASYIO }, |
| 218 | { "eio", BRD_EASYIO }, |
| 219 | { "20", BRD_EASYIO }, |
| 220 | { "ec8/32", BRD_ECH }, |
| 221 | { "ec8/32-at", BRD_ECH }, |
| 222 | { "ec8/32-isa", BRD_ECH }, |
| 223 | { "ech", BRD_ECH }, |
| 224 | { "echat", BRD_ECH }, |
| 225 | { "21", BRD_ECH }, |
| 226 | { "ec8/32-mc", BRD_ECHMC }, |
| 227 | { "ec8/32-mca", BRD_ECHMC }, |
| 228 | { "echmc", BRD_ECHMC }, |
| 229 | { "echmca", BRD_ECHMC }, |
| 230 | { "22", BRD_ECHMC }, |
| 231 | { "ec8/32-pc", BRD_ECHPCI }, |
| 232 | { "ec8/32-pci", BRD_ECHPCI }, |
| 233 | { "26", BRD_ECHPCI }, |
| 234 | { "ec8/64-pc", BRD_ECH64PCI }, |
| 235 | { "ec8/64-pci", BRD_ECH64PCI }, |
| 236 | { "ech-pci", BRD_ECH64PCI }, |
| 237 | { "echpci", BRD_ECH64PCI }, |
| 238 | { "echpc", BRD_ECH64PCI }, |
| 239 | { "27", BRD_ECH64PCI }, |
| 240 | { "easyio-pc", BRD_EASYIOPCI }, |
| 241 | { "easyio-pci", BRD_EASYIOPCI }, |
| 242 | { "eio-pci", BRD_EASYIOPCI }, |
| 243 | { "eiopci", BRD_EASYIOPCI }, |
| 244 | { "28", BRD_EASYIOPCI }, |
| 245 | }; |
| 246 | |
| 247 | /* |
| 248 | * Define the module agruments. |
| 249 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | |
| 251 | module_param_array(board0, charp, &stl_nargs, 0); |
| 252 | MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,ioaddr2][,irq]]"); |
| 253 | module_param_array(board1, charp, &stl_nargs, 0); |
| 254 | MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,ioaddr2][,irq]]"); |
| 255 | module_param_array(board2, charp, &stl_nargs, 0); |
| 256 | MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,ioaddr2][,irq]]"); |
| 257 | module_param_array(board3, charp, &stl_nargs, 0); |
| 258 | MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,ioaddr2][,irq]]"); |
| 259 | |
| 260 | /*****************************************************************************/ |
| 261 | |
| 262 | /* |
| 263 | * Hardware ID bits for the EasyIO and ECH boards. These defines apply |
| 264 | * to the directly accessible io ports of these boards (not the uarts - |
| 265 | * they are in cd1400.h and sc26198.h). |
| 266 | */ |
| 267 | #define EIO_8PORTRS 0x04 |
| 268 | #define EIO_4PORTRS 0x05 |
| 269 | #define EIO_8PORTDI 0x00 |
| 270 | #define EIO_8PORTM 0x06 |
| 271 | #define EIO_MK3 0x03 |
| 272 | #define EIO_IDBITMASK 0x07 |
| 273 | |
| 274 | #define EIO_BRDMASK 0xf0 |
| 275 | #define ID_BRD4 0x10 |
| 276 | #define ID_BRD8 0x20 |
| 277 | #define ID_BRD16 0x30 |
| 278 | |
| 279 | #define EIO_INTRPEND 0x08 |
| 280 | #define EIO_INTEDGE 0x00 |
| 281 | #define EIO_INTLEVEL 0x08 |
| 282 | #define EIO_0WS 0x10 |
| 283 | |
| 284 | #define ECH_ID 0xa0 |
| 285 | #define ECH_IDBITMASK 0xe0 |
| 286 | #define ECH_BRDENABLE 0x08 |
| 287 | #define ECH_BRDDISABLE 0x00 |
| 288 | #define ECH_INTENABLE 0x01 |
| 289 | #define ECH_INTDISABLE 0x00 |
| 290 | #define ECH_INTLEVEL 0x02 |
| 291 | #define ECH_INTEDGE 0x00 |
| 292 | #define ECH_INTRPEND 0x01 |
| 293 | #define ECH_BRDRESET 0x01 |
| 294 | |
| 295 | #define ECHMC_INTENABLE 0x01 |
| 296 | #define ECHMC_BRDRESET 0x02 |
| 297 | |
| 298 | #define ECH_PNLSTATUS 2 |
| 299 | #define ECH_PNL16PORT 0x20 |
| 300 | #define ECH_PNLIDMASK 0x07 |
| 301 | #define ECH_PNLXPID 0x40 |
| 302 | #define ECH_PNLINTRPEND 0x80 |
| 303 | |
| 304 | #define ECH_ADDR2MASK 0x1e0 |
| 305 | |
| 306 | /* |
| 307 | * Define the vector mapping bits for the programmable interrupt board |
| 308 | * hardware. These bits encode the interrupt for the board to use - it |
| 309 | * is software selectable (except the EIO-8M). |
| 310 | */ |
| 311 | static unsigned char stl_vecmap[] = { |
| 312 | 0xff, 0xff, 0xff, 0x04, 0x06, 0x05, 0xff, 0x07, |
| 313 | 0xff, 0xff, 0x00, 0x02, 0x01, 0xff, 0xff, 0x03 |
| 314 | }; |
| 315 | |
| 316 | /* |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 317 | * Lock ordering is that you may not take stallion_lock holding |
| 318 | * brd_lock. |
| 319 | */ |
| 320 | |
| 321 | static spinlock_t brd_lock; /* Guard the board mapping */ |
| 322 | static spinlock_t stallion_lock; /* Guard the tty driver */ |
| 323 | |
| 324 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | * Set up enable and disable macros for the ECH boards. They require |
| 326 | * the secondary io address space to be activated and deactivated. |
| 327 | * This way all ECH boards can share their secondary io region. |
| 328 | * If this is an ECH-PCI board then also need to set the page pointer |
| 329 | * to point to the correct page. |
| 330 | */ |
| 331 | #define BRDENABLE(brdnr,pagenr) \ |
| 332 | if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \ |
| 333 | outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDENABLE), \ |
| 334 | stl_brds[(brdnr)]->ioctrl); \ |
| 335 | else if (stl_brds[(brdnr)]->brdtype == BRD_ECHPCI) \ |
| 336 | outb((pagenr), stl_brds[(brdnr)]->ioctrl); |
| 337 | |
| 338 | #define BRDDISABLE(brdnr) \ |
| 339 | if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \ |
| 340 | outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDDISABLE), \ |
| 341 | stl_brds[(brdnr)]->ioctrl); |
| 342 | |
| 343 | #define STL_CD1400MAXBAUD 230400 |
| 344 | #define STL_SC26198MAXBAUD 460800 |
| 345 | |
| 346 | #define STL_BAUDBASE 115200 |
| 347 | #define STL_CLOSEDELAY (5 * HZ / 10) |
| 348 | |
| 349 | /*****************************************************************************/ |
| 350 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | /* |
| 352 | * Define the Stallion PCI vendor and device IDs. |
| 353 | */ |
| 354 | #ifndef PCI_VENDOR_ID_STALLION |
| 355 | #define PCI_VENDOR_ID_STALLION 0x124d |
| 356 | #endif |
| 357 | #ifndef PCI_DEVICE_ID_ECHPCI832 |
| 358 | #define PCI_DEVICE_ID_ECHPCI832 0x0000 |
| 359 | #endif |
| 360 | #ifndef PCI_DEVICE_ID_ECHPCI864 |
| 361 | #define PCI_DEVICE_ID_ECHPCI864 0x0002 |
| 362 | #endif |
| 363 | #ifndef PCI_DEVICE_ID_EIOPCI |
| 364 | #define PCI_DEVICE_ID_EIOPCI 0x0003 |
| 365 | #endif |
| 366 | |
| 367 | /* |
| 368 | * Define structure to hold all Stallion PCI boards. |
| 369 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | |
Jiri Slaby | b1b84fe | 2006-12-08 02:39:09 -0800 | [diff] [blame] | 371 | static struct pci_device_id stl_pcibrds[] = { |
| 372 | { PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI864), |
| 373 | .driver_data = BRD_ECH64PCI }, |
| 374 | { PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_EIOPCI), |
| 375 | .driver_data = BRD_EASYIOPCI }, |
| 376 | { PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI832), |
| 377 | .driver_data = BRD_ECHPCI }, |
| 378 | { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87410), |
| 379 | .driver_data = BRD_ECHPCI }, |
| 380 | { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | }; |
Jiri Slaby | b1b84fe | 2006-12-08 02:39:09 -0800 | [diff] [blame] | 382 | MODULE_DEVICE_TABLE(pci, stl_pcibrds); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | |
| 384 | /*****************************************************************************/ |
| 385 | |
| 386 | /* |
| 387 | * Define macros to extract a brd/port number from a minor number. |
| 388 | */ |
| 389 | #define MINOR2BRD(min) (((min) & 0xc0) >> 6) |
| 390 | #define MINOR2PORT(min) ((min) & 0x3f) |
| 391 | |
| 392 | /* |
| 393 | * Define a baud rate table that converts termios baud rate selector |
| 394 | * into the actual baud rate value. All baud rate calculations are |
| 395 | * based on the actual baud rate required. |
| 396 | */ |
| 397 | static unsigned int stl_baudrates[] = { |
| 398 | 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, |
| 399 | 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600 |
| 400 | }; |
| 401 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | /*****************************************************************************/ |
| 403 | |
| 404 | /* |
| 405 | * Declare all those functions in this driver! |
| 406 | */ |
| 407 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg); |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 409 | static int stl_brdinit(struct stlbrd *brdp); |
Alan Cox | d18a750 | 2008-10-13 10:40:07 +0100 | [diff] [blame] | 410 | static int stl_getportstats(struct tty_struct *tty, struct stlport *portp, comstats_t __user *cp); |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 411 | static int stl_clrportstats(struct stlport *portp, comstats_t __user *cp); |
Alan Cox | d18a750 | 2008-10-13 10:40:07 +0100 | [diff] [blame] | 412 | static int stl_waitcarrier(struct tty_struct *tty, struct stlport *portp, struct file *filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | /* |
| 415 | * CD1400 uart specific handling functions. |
| 416 | */ |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 417 | static void stl_cd1400setreg(struct stlport *portp, int regnr, int value); |
| 418 | static int stl_cd1400getreg(struct stlport *portp, int regnr); |
| 419 | static int stl_cd1400updatereg(struct stlport *portp, int regnr, int value); |
| 420 | static int stl_cd1400panelinit(struct stlbrd *brdp, struct stlpanel *panelp); |
| 421 | static void stl_cd1400portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp); |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 422 | static void stl_cd1400setport(struct stlport *portp, struct ktermios *tiosp); |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 423 | static int stl_cd1400getsignals(struct stlport *portp); |
| 424 | static void stl_cd1400setsignals(struct stlport *portp, int dtr, int rts); |
| 425 | static void stl_cd1400ccrwait(struct stlport *portp); |
| 426 | static void stl_cd1400enablerxtx(struct stlport *portp, int rx, int tx); |
| 427 | static void stl_cd1400startrxtx(struct stlport *portp, int rx, int tx); |
| 428 | static void stl_cd1400disableintrs(struct stlport *portp); |
| 429 | static void stl_cd1400sendbreak(struct stlport *portp, int len); |
| 430 | static void stl_cd1400flowctrl(struct stlport *portp, int state); |
| 431 | static void stl_cd1400sendflow(struct stlport *portp, int state); |
| 432 | static void stl_cd1400flush(struct stlport *portp); |
| 433 | static int stl_cd1400datastate(struct stlport *portp); |
| 434 | static void stl_cd1400eiointr(struct stlpanel *panelp, unsigned int iobase); |
| 435 | static void stl_cd1400echintr(struct stlpanel *panelp, unsigned int iobase); |
| 436 | static void stl_cd1400txisr(struct stlpanel *panelp, int ioaddr); |
| 437 | static void stl_cd1400rxisr(struct stlpanel *panelp, int ioaddr); |
| 438 | static void stl_cd1400mdmisr(struct stlpanel *panelp, int ioaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 440 | static inline int stl_cd1400breakisr(struct stlport *portp, int ioaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | |
| 442 | /* |
| 443 | * SC26198 uart specific handling functions. |
| 444 | */ |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 445 | static void stl_sc26198setreg(struct stlport *portp, int regnr, int value); |
| 446 | static int stl_sc26198getreg(struct stlport *portp, int regnr); |
| 447 | static int stl_sc26198updatereg(struct stlport *portp, int regnr, int value); |
| 448 | static int stl_sc26198getglobreg(struct stlport *portp, int regnr); |
| 449 | static int stl_sc26198panelinit(struct stlbrd *brdp, struct stlpanel *panelp); |
| 450 | static void stl_sc26198portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp); |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 451 | static void stl_sc26198setport(struct stlport *portp, struct ktermios *tiosp); |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 452 | static int stl_sc26198getsignals(struct stlport *portp); |
| 453 | static void stl_sc26198setsignals(struct stlport *portp, int dtr, int rts); |
| 454 | static void stl_sc26198enablerxtx(struct stlport *portp, int rx, int tx); |
| 455 | static void stl_sc26198startrxtx(struct stlport *portp, int rx, int tx); |
| 456 | static void stl_sc26198disableintrs(struct stlport *portp); |
| 457 | static void stl_sc26198sendbreak(struct stlport *portp, int len); |
| 458 | static void stl_sc26198flowctrl(struct stlport *portp, int state); |
| 459 | static void stl_sc26198sendflow(struct stlport *portp, int state); |
| 460 | static void stl_sc26198flush(struct stlport *portp); |
| 461 | static int stl_sc26198datastate(struct stlport *portp); |
| 462 | static void stl_sc26198wait(struct stlport *portp); |
| 463 | static void stl_sc26198txunflow(struct stlport *portp, struct tty_struct *tty); |
| 464 | static void stl_sc26198intr(struct stlpanel *panelp, unsigned int iobase); |
| 465 | static void stl_sc26198txisr(struct stlport *port); |
| 466 | static void stl_sc26198rxisr(struct stlport *port, unsigned int iack); |
| 467 | static void stl_sc26198rxbadch(struct stlport *portp, unsigned char status, char ch); |
| 468 | static void stl_sc26198rxbadchars(struct stlport *portp); |
| 469 | static void stl_sc26198otherisr(struct stlport *port, unsigned int iack); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | |
| 471 | /*****************************************************************************/ |
| 472 | |
| 473 | /* |
| 474 | * Generic UART support structure. |
| 475 | */ |
| 476 | typedef struct uart { |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 477 | int (*panelinit)(struct stlbrd *brdp, struct stlpanel *panelp); |
| 478 | void (*portinit)(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp); |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 479 | void (*setport)(struct stlport *portp, struct ktermios *tiosp); |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 480 | int (*getsignals)(struct stlport *portp); |
| 481 | void (*setsignals)(struct stlport *portp, int dtr, int rts); |
| 482 | void (*enablerxtx)(struct stlport *portp, int rx, int tx); |
| 483 | void (*startrxtx)(struct stlport *portp, int rx, int tx); |
| 484 | void (*disableintrs)(struct stlport *portp); |
| 485 | void (*sendbreak)(struct stlport *portp, int len); |
| 486 | void (*flowctrl)(struct stlport *portp, int state); |
| 487 | void (*sendflow)(struct stlport *portp, int state); |
| 488 | void (*flush)(struct stlport *portp); |
| 489 | int (*datastate)(struct stlport *portp); |
| 490 | void (*intr)(struct stlpanel *panelp, unsigned int iobase); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | } uart_t; |
| 492 | |
| 493 | /* |
| 494 | * Define some macros to make calling these functions nice and clean. |
| 495 | */ |
| 496 | #define stl_panelinit (* ((uart_t *) panelp->uartp)->panelinit) |
| 497 | #define stl_portinit (* ((uart_t *) portp->uartp)->portinit) |
| 498 | #define stl_setport (* ((uart_t *) portp->uartp)->setport) |
| 499 | #define stl_getsignals (* ((uart_t *) portp->uartp)->getsignals) |
| 500 | #define stl_setsignals (* ((uart_t *) portp->uartp)->setsignals) |
| 501 | #define stl_enablerxtx (* ((uart_t *) portp->uartp)->enablerxtx) |
| 502 | #define stl_startrxtx (* ((uart_t *) portp->uartp)->startrxtx) |
| 503 | #define stl_disableintrs (* ((uart_t *) portp->uartp)->disableintrs) |
| 504 | #define stl_sendbreak (* ((uart_t *) portp->uartp)->sendbreak) |
| 505 | #define stl_flowctrl (* ((uart_t *) portp->uartp)->flowctrl) |
| 506 | #define stl_sendflow (* ((uart_t *) portp->uartp)->sendflow) |
| 507 | #define stl_flush (* ((uart_t *) portp->uartp)->flush) |
| 508 | #define stl_datastate (* ((uart_t *) portp->uartp)->datastate) |
| 509 | |
| 510 | /*****************************************************************************/ |
| 511 | |
| 512 | /* |
| 513 | * CD1400 UART specific data initialization. |
| 514 | */ |
| 515 | static uart_t stl_cd1400uart = { |
| 516 | stl_cd1400panelinit, |
| 517 | stl_cd1400portinit, |
| 518 | stl_cd1400setport, |
| 519 | stl_cd1400getsignals, |
| 520 | stl_cd1400setsignals, |
| 521 | stl_cd1400enablerxtx, |
| 522 | stl_cd1400startrxtx, |
| 523 | stl_cd1400disableintrs, |
| 524 | stl_cd1400sendbreak, |
| 525 | stl_cd1400flowctrl, |
| 526 | stl_cd1400sendflow, |
| 527 | stl_cd1400flush, |
| 528 | stl_cd1400datastate, |
| 529 | stl_cd1400eiointr |
| 530 | }; |
| 531 | |
| 532 | /* |
| 533 | * Define the offsets within the register bank of a cd1400 based panel. |
| 534 | * These io address offsets are common to the EasyIO board as well. |
| 535 | */ |
| 536 | #define EREG_ADDR 0 |
| 537 | #define EREG_DATA 4 |
| 538 | #define EREG_RXACK 5 |
| 539 | #define EREG_TXACK 6 |
| 540 | #define EREG_MDACK 7 |
| 541 | |
| 542 | #define EREG_BANKSIZE 8 |
| 543 | |
| 544 | #define CD1400_CLK 25000000 |
| 545 | #define CD1400_CLK8M 20000000 |
| 546 | |
| 547 | /* |
| 548 | * Define the cd1400 baud rate clocks. These are used when calculating |
| 549 | * what clock and divisor to use for the required baud rate. Also |
| 550 | * define the maximum baud rate allowed, and the default base baud. |
| 551 | */ |
| 552 | static int stl_cd1400clkdivs[] = { |
| 553 | CD1400_CLK0, CD1400_CLK1, CD1400_CLK2, CD1400_CLK3, CD1400_CLK4 |
| 554 | }; |
| 555 | |
| 556 | /*****************************************************************************/ |
| 557 | |
| 558 | /* |
| 559 | * SC26198 UART specific data initization. |
| 560 | */ |
| 561 | static uart_t stl_sc26198uart = { |
| 562 | stl_sc26198panelinit, |
| 563 | stl_sc26198portinit, |
| 564 | stl_sc26198setport, |
| 565 | stl_sc26198getsignals, |
| 566 | stl_sc26198setsignals, |
| 567 | stl_sc26198enablerxtx, |
| 568 | stl_sc26198startrxtx, |
| 569 | stl_sc26198disableintrs, |
| 570 | stl_sc26198sendbreak, |
| 571 | stl_sc26198flowctrl, |
| 572 | stl_sc26198sendflow, |
| 573 | stl_sc26198flush, |
| 574 | stl_sc26198datastate, |
| 575 | stl_sc26198intr |
| 576 | }; |
| 577 | |
| 578 | /* |
| 579 | * Define the offsets within the register bank of a sc26198 based panel. |
| 580 | */ |
| 581 | #define XP_DATA 0 |
| 582 | #define XP_ADDR 1 |
| 583 | #define XP_MODID 2 |
| 584 | #define XP_STATUS 2 |
| 585 | #define XP_IACK 3 |
| 586 | |
| 587 | #define XP_BANKSIZE 4 |
| 588 | |
| 589 | /* |
| 590 | * Define the sc26198 baud rate table. Offsets within the table |
| 591 | * represent the actual baud rate selector of sc26198 registers. |
| 592 | */ |
| 593 | static unsigned int sc26198_baudtable[] = { |
| 594 | 50, 75, 150, 200, 300, 450, 600, 900, 1200, 1800, 2400, 3600, |
| 595 | 4800, 7200, 9600, 14400, 19200, 28800, 38400, 57600, 115200, |
| 596 | 230400, 460800, 921600 |
| 597 | }; |
| 598 | |
Tobias Klauser | fe97107 | 2006-01-09 20:54:02 -0800 | [diff] [blame] | 599 | #define SC26198_NRBAUDS ARRAY_SIZE(sc26198_baudtable) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | |
| 601 | /*****************************************************************************/ |
| 602 | |
| 603 | /* |
| 604 | * Define the driver info for a user level control device. Used mainly |
| 605 | * to get at port stats - only not using the port device itself. |
| 606 | */ |
Arjan van de Ven | 62322d2 | 2006-07-03 00:24:21 -0700 | [diff] [blame] | 607 | static const struct file_operations stl_fsiomem = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | .owner = THIS_MODULE, |
| 609 | .ioctl = stl_memioctl, |
| 610 | }; |
| 611 | |
gregkh@suse.de | ca8eca6 | 2005-03-23 09:53:09 -0800 | [diff] [blame] | 612 | static struct class *stallion_class; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | |
Jiri Slaby | ccfea3c | 2008-02-07 00:16:39 -0800 | [diff] [blame] | 614 | static void stl_cd_change(struct stlport *portp) |
| 615 | { |
| 616 | unsigned int oldsigs = portp->sigs; |
Alan Cox | d18a750 | 2008-10-13 10:40:07 +0100 | [diff] [blame] | 617 | struct tty_struct *tty = tty_port_tty_get(&portp->port); |
Jiri Slaby | ccfea3c | 2008-02-07 00:16:39 -0800 | [diff] [blame] | 618 | |
Alan Cox | d18a750 | 2008-10-13 10:40:07 +0100 | [diff] [blame] | 619 | if (!tty) |
Jiri Slaby | ccfea3c | 2008-02-07 00:16:39 -0800 | [diff] [blame] | 620 | return; |
| 621 | |
| 622 | portp->sigs = stl_getsignals(portp); |
| 623 | |
| 624 | if ((portp->sigs & TIOCM_CD) && ((oldsigs & TIOCM_CD) == 0)) |
Alan Cox | f8ae476 | 2008-07-16 21:56:37 +0100 | [diff] [blame] | 625 | wake_up_interruptible(&portp->port.open_wait); |
Jiri Slaby | ccfea3c | 2008-02-07 00:16:39 -0800 | [diff] [blame] | 626 | |
| 627 | if ((oldsigs & TIOCM_CD) && ((portp->sigs & TIOCM_CD) == 0)) |
Alan Cox | f8ae476 | 2008-07-16 21:56:37 +0100 | [diff] [blame] | 628 | if (portp->port.flags & ASYNC_CHECK_CD) |
Alan Cox | d18a750 | 2008-10-13 10:40:07 +0100 | [diff] [blame] | 629 | tty_hangup(tty); |
| 630 | tty_kref_put(tty); |
Jiri Slaby | ccfea3c | 2008-02-07 00:16:39 -0800 | [diff] [blame] | 631 | } |
| 632 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | * Check for any arguments passed in on the module load command line. |
| 635 | */ |
| 636 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | /*****************************************************************************/ |
| 638 | |
| 639 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | * Parse the supplied argument string, into the board conf struct. |
| 641 | */ |
| 642 | |
Jiri Slaby | 40e8265 | 2006-12-08 02:38:41 -0800 | [diff] [blame] | 643 | static int __init stl_parsebrd(struct stlconf *confp, char **argp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | { |
| 645 | char *sp; |
Jiri Slaby | 6b2c945 | 2006-12-08 02:39:15 -0800 | [diff] [blame] | 646 | unsigned int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 648 | pr_debug("stl_parsebrd(confp=%p,argp=%p)\n", confp, argp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 650 | if ((argp[0] == NULL) || (*argp[0] == 0)) |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 651 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 653 | for (sp = argp[0], i = 0; (*sp != 0) && (i < 25); sp++, i++) |
Jiri Slaby | 843b568 | 2006-12-08 02:39:12 -0800 | [diff] [blame] | 654 | *sp = tolower(*sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 656 | for (i = 0; i < ARRAY_SIZE(stl_brdstr); i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | if (strcmp(stl_brdstr[i].name, argp[0]) == 0) |
| 658 | break; |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 659 | |
Tobias Klauser | fe97107 | 2006-01-09 20:54:02 -0800 | [diff] [blame] | 660 | if (i == ARRAY_SIZE(stl_brdstr)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | printk("STALLION: unknown board name, %s?\n", argp[0]); |
Tobias Klauser | fe97107 | 2006-01-09 20:54:02 -0800 | [diff] [blame] | 662 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | confp->brdtype = stl_brdstr[i].type; |
| 666 | |
| 667 | i = 1; |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 668 | if ((argp[i] != NULL) && (*argp[i] != 0)) |
Jiri Slaby | 843b568 | 2006-12-08 02:39:12 -0800 | [diff] [blame] | 669 | confp->ioaddr1 = simple_strtoul(argp[i], NULL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | i++; |
| 671 | if (confp->brdtype == BRD_ECH) { |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 672 | if ((argp[i] != NULL) && (*argp[i] != 0)) |
Jiri Slaby | 843b568 | 2006-12-08 02:39:12 -0800 | [diff] [blame] | 673 | confp->ioaddr2 = simple_strtoul(argp[i], NULL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | i++; |
| 675 | } |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 676 | if ((argp[i] != NULL) && (*argp[i] != 0)) |
Jiri Slaby | 843b568 | 2006-12-08 02:39:12 -0800 | [diff] [blame] | 677 | confp->irq = simple_strtoul(argp[i], NULL, 0); |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 678 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | /*****************************************************************************/ |
| 682 | |
| 683 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | * Allocate a new board structure. Fill out the basic info in it. |
| 685 | */ |
| 686 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 687 | static struct stlbrd *stl_allocbrd(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | { |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 689 | struct stlbrd *brdp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 691 | brdp = kzalloc(sizeof(struct stlbrd), GFP_KERNEL); |
Tobias Klauser | b0b4ed7 | 2006-03-31 02:30:56 -0800 | [diff] [blame] | 692 | if (!brdp) { |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 693 | printk("STALLION: failed to allocate memory (size=%Zd)\n", |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 694 | sizeof(struct stlbrd)); |
Tobias Klauser | b0b4ed7 | 2006-03-31 02:30:56 -0800 | [diff] [blame] | 695 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | } |
| 697 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | brdp->magic = STL_BOARDMAGIC; |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 699 | return brdp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | /*****************************************************************************/ |
| 703 | |
| 704 | static int stl_open(struct tty_struct *tty, struct file *filp) |
| 705 | { |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 706 | struct stlport *portp; |
| 707 | struct stlbrd *brdp; |
Jiri Slaby | 6b2c945 | 2006-12-08 02:39:15 -0800 | [diff] [blame] | 708 | unsigned int minordev, brdnr, panelnr; |
| 709 | int portnr, rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 711 | pr_debug("stl_open(tty=%p,filp=%p): device=%s\n", tty, filp, tty->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | |
| 713 | minordev = tty->index; |
| 714 | brdnr = MINOR2BRD(minordev); |
| 715 | if (brdnr >= stl_nrbrds) |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 716 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | brdp = stl_brds[brdnr]; |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 718 | if (brdp == NULL) |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 719 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | minordev = MINOR2PORT(minordev); |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 721 | for (portnr = -1, panelnr = 0; panelnr < STL_MAXPANELS; panelnr++) { |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 722 | if (brdp->panels[panelnr] == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | break; |
| 724 | if (minordev < brdp->panels[panelnr]->nrports) { |
| 725 | portnr = minordev; |
| 726 | break; |
| 727 | } |
| 728 | minordev -= brdp->panels[panelnr]->nrports; |
| 729 | } |
| 730 | if (portnr < 0) |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 731 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | |
| 733 | portp = brdp->panels[panelnr]->ports[portnr]; |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 734 | if (portp == NULL) |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 735 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | |
| 737 | /* |
| 738 | * On the first open of the device setup the port hardware, and |
| 739 | * initialize the per port data structure. |
| 740 | */ |
Alan Cox | d18a750 | 2008-10-13 10:40:07 +0100 | [diff] [blame] | 741 | tty_port_tty_set(&portp->port, tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | tty->driver_data = portp; |
Alan Cox | f8ae476 | 2008-07-16 21:56:37 +0100 | [diff] [blame] | 743 | portp->port.count++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | |
Alan Cox | f8ae476 | 2008-07-16 21:56:37 +0100 | [diff] [blame] | 745 | if ((portp->port.flags & ASYNC_INITIALIZED) == 0) { |
Tobias Klauser | b0b4ed7 | 2006-03-31 02:30:56 -0800 | [diff] [blame] | 746 | if (!portp->tx.buf) { |
| 747 | portp->tx.buf = kmalloc(STL_TXBUFSIZE, GFP_KERNEL); |
| 748 | if (!portp->tx.buf) |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 749 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | portp->tx.head = portp->tx.buf; |
| 751 | portp->tx.tail = portp->tx.buf; |
| 752 | } |
| 753 | stl_setport(portp, tty->termios); |
| 754 | portp->sigs = stl_getsignals(portp); |
| 755 | stl_setsignals(portp, 1, 1); |
| 756 | stl_enablerxtx(portp, 1, 1); |
| 757 | stl_startrxtx(portp, 1, 0); |
| 758 | clear_bit(TTY_IO_ERROR, &tty->flags); |
Alan Cox | f8ae476 | 2008-07-16 21:56:37 +0100 | [diff] [blame] | 759 | portp->port.flags |= ASYNC_INITIALIZED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | /* |
| 763 | * Check if this port is in the middle of closing. If so then wait |
| 764 | * until it is closed then return error status, based on flag settings. |
| 765 | * The sleep here does not need interrupt protection since the wakeup |
| 766 | * for it is done with the same context. |
| 767 | */ |
Alan Cox | f8ae476 | 2008-07-16 21:56:37 +0100 | [diff] [blame] | 768 | if (portp->port.flags & ASYNC_CLOSING) { |
| 769 | interruptible_sleep_on(&portp->port.close_wait); |
| 770 | if (portp->port.flags & ASYNC_HUP_NOTIFY) |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 771 | return -EAGAIN; |
| 772 | return -ERESTARTSYS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | /* |
| 776 | * Based on type of open being done check if it can overlap with any |
| 777 | * previous opens still in effect. If we are a normal serial device |
| 778 | * then also we might have to wait for carrier. |
| 779 | */ |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 780 | if (!(filp->f_flags & O_NONBLOCK)) |
Alan Cox | d18a750 | 2008-10-13 10:40:07 +0100 | [diff] [blame] | 781 | if ((rc = stl_waitcarrier(tty, portp, filp)) != 0) |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 782 | return rc; |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 783 | |
Alan Cox | f8ae476 | 2008-07-16 21:56:37 +0100 | [diff] [blame] | 784 | portp->port.flags |= ASYNC_NORMAL_ACTIVE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 786 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | } |
| 788 | |
| 789 | /*****************************************************************************/ |
| 790 | |
Alan Cox | 31f3593 | 2009-01-02 13:45:05 +0000 | [diff] [blame^] | 791 | static int stl_carrier_raised(struct tty_port *port) |
| 792 | { |
| 793 | struct stlport *portp = container_of(port, struct stlport, port); |
| 794 | return (portp->sigs & TIOCM_CD) ? 1 : 0; |
| 795 | } |
| 796 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | /* |
| 798 | * Possibly need to wait for carrier (DCD signal) to come high. Say |
| 799 | * maybe because if we are clocal then we don't need to wait... |
| 800 | */ |
| 801 | |
Alan Cox | d18a750 | 2008-10-13 10:40:07 +0100 | [diff] [blame] | 802 | static int stl_waitcarrier(struct tty_struct *tty, struct stlport *portp, |
| 803 | struct file *filp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | { |
| 805 | unsigned long flags; |
| 806 | int rc, doclocal; |
Alan Cox | 31f3593 | 2009-01-02 13:45:05 +0000 | [diff] [blame^] | 807 | struct tty_port *port = &portp->port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 809 | pr_debug("stl_waitcarrier(portp=%p,filp=%p)\n", portp, filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | |
| 811 | rc = 0; |
| 812 | doclocal = 0; |
| 813 | |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 814 | spin_lock_irqsave(&stallion_lock, flags); |
| 815 | |
Alan Cox | d18a750 | 2008-10-13 10:40:07 +0100 | [diff] [blame] | 816 | if (tty->termios->c_cflag & CLOCAL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | doclocal++; |
| 818 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | portp->openwaitcnt++; |
| 820 | if (! tty_hung_up_p(filp)) |
Alan Cox | 31f3593 | 2009-01-02 13:45:05 +0000 | [diff] [blame^] | 821 | port->count--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | |
| 823 | for (;;) { |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 824 | /* Takes brd_lock internally */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | stl_setsignals(portp, 1, 1); |
| 826 | if (tty_hung_up_p(filp) || |
Alan Cox | 31f3593 | 2009-01-02 13:45:05 +0000 | [diff] [blame^] | 827 | ((port->flags & ASYNC_INITIALIZED) == 0)) { |
| 828 | if (port->flags & ASYNC_HUP_NOTIFY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | rc = -EBUSY; |
| 830 | else |
| 831 | rc = -ERESTARTSYS; |
| 832 | break; |
| 833 | } |
Alan Cox | 31f3593 | 2009-01-02 13:45:05 +0000 | [diff] [blame^] | 834 | if (((port->flags & ASYNC_CLOSING) == 0) && |
| 835 | (doclocal || tty_port_carrier_raised(port))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | if (signal_pending(current)) { |
| 838 | rc = -ERESTARTSYS; |
| 839 | break; |
| 840 | } |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 841 | /* FIXME */ |
Alan Cox | 31f3593 | 2009-01-02 13:45:05 +0000 | [diff] [blame^] | 842 | interruptible_sleep_on(&port->open_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | if (! tty_hung_up_p(filp)) |
Alan Cox | 31f3593 | 2009-01-02 13:45:05 +0000 | [diff] [blame^] | 846 | port->count++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | portp->openwaitcnt--; |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 848 | spin_unlock_irqrestore(&stallion_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 850 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | /*****************************************************************************/ |
| 854 | |
Jiri Slaby | 96b066b | 2006-12-08 02:38:42 -0800 | [diff] [blame] | 855 | static void stl_flushbuffer(struct tty_struct *tty) |
| 856 | { |
| 857 | struct stlport *portp; |
| 858 | |
| 859 | pr_debug("stl_flushbuffer(tty=%p)\n", tty); |
| 860 | |
Jiri Slaby | 96b066b | 2006-12-08 02:38:42 -0800 | [diff] [blame] | 861 | portp = tty->driver_data; |
| 862 | if (portp == NULL) |
| 863 | return; |
| 864 | |
| 865 | stl_flush(portp); |
| 866 | tty_wakeup(tty); |
| 867 | } |
| 868 | |
| 869 | /*****************************************************************************/ |
| 870 | |
| 871 | static void stl_waituntilsent(struct tty_struct *tty, int timeout) |
| 872 | { |
| 873 | struct stlport *portp; |
| 874 | unsigned long tend; |
| 875 | |
| 876 | pr_debug("stl_waituntilsent(tty=%p,timeout=%d)\n", tty, timeout); |
| 877 | |
Jiri Slaby | 96b066b | 2006-12-08 02:38:42 -0800 | [diff] [blame] | 878 | portp = tty->driver_data; |
| 879 | if (portp == NULL) |
| 880 | return; |
| 881 | |
| 882 | if (timeout == 0) |
| 883 | timeout = HZ; |
| 884 | tend = jiffies + timeout; |
| 885 | |
Alan Cox | 978e595 | 2008-04-30 00:53:59 -0700 | [diff] [blame] | 886 | lock_kernel(); |
Jiri Slaby | 96b066b | 2006-12-08 02:38:42 -0800 | [diff] [blame] | 887 | while (stl_datastate(portp)) { |
| 888 | if (signal_pending(current)) |
| 889 | break; |
| 890 | msleep_interruptible(20); |
| 891 | if (time_after_eq(jiffies, tend)) |
| 892 | break; |
| 893 | } |
Alan Cox | 978e595 | 2008-04-30 00:53:59 -0700 | [diff] [blame] | 894 | unlock_kernel(); |
Jiri Slaby | 96b066b | 2006-12-08 02:38:42 -0800 | [diff] [blame] | 895 | } |
| 896 | |
| 897 | /*****************************************************************************/ |
| 898 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | static void stl_close(struct tty_struct *tty, struct file *filp) |
| 900 | { |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 901 | struct stlport *portp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | unsigned long flags; |
| 903 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 904 | pr_debug("stl_close(tty=%p,filp=%p)\n", tty, filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | |
| 906 | portp = tty->driver_data; |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 907 | if (portp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | return; |
| 909 | |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 910 | spin_lock_irqsave(&stallion_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | if (tty_hung_up_p(filp)) { |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 912 | spin_unlock_irqrestore(&stallion_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | return; |
| 914 | } |
Alan Cox | f8ae476 | 2008-07-16 21:56:37 +0100 | [diff] [blame] | 915 | if ((tty->count == 1) && (portp->port.count != 1)) |
| 916 | portp->port.count = 1; |
| 917 | if (portp->port.count-- > 1) { |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 918 | spin_unlock_irqrestore(&stallion_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | return; |
| 920 | } |
| 921 | |
Alan Cox | f8ae476 | 2008-07-16 21:56:37 +0100 | [diff] [blame] | 922 | portp->port.count = 0; |
| 923 | portp->port.flags |= ASYNC_CLOSING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | |
| 925 | /* |
| 926 | * May want to wait for any data to drain before closing. The BUSY |
| 927 | * flag keeps track of whether we are still sending or not - it is |
| 928 | * very accurate for the cd1400, not quite so for the sc26198. |
| 929 | * (The sc26198 has no "end-of-data" interrupt only empty FIFO) |
| 930 | */ |
| 931 | tty->closing = 1; |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 932 | |
| 933 | spin_unlock_irqrestore(&stallion_lock, flags); |
| 934 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE) |
| 936 | tty_wait_until_sent(tty, portp->closing_wait); |
| 937 | stl_waituntilsent(tty, (HZ / 2)); |
| 938 | |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 939 | |
| 940 | spin_lock_irqsave(&stallion_lock, flags); |
Alan Cox | f8ae476 | 2008-07-16 21:56:37 +0100 | [diff] [blame] | 941 | portp->port.flags &= ~ASYNC_INITIALIZED; |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 942 | spin_unlock_irqrestore(&stallion_lock, flags); |
| 943 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | stl_disableintrs(portp); |
| 945 | if (tty->termios->c_cflag & HUPCL) |
| 946 | stl_setsignals(portp, 0, 0); |
| 947 | stl_enablerxtx(portp, 0, 0); |
| 948 | stl_flushbuffer(tty); |
| 949 | portp->istate = 0; |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 950 | if (portp->tx.buf != NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | kfree(portp->tx.buf); |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 952 | portp->tx.buf = NULL; |
| 953 | portp->tx.head = NULL; |
| 954 | portp->tx.tail = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | } |
| 956 | set_bit(TTY_IO_ERROR, &tty->flags); |
| 957 | tty_ldisc_flush(tty); |
| 958 | |
| 959 | tty->closing = 0; |
Alan Cox | d18a750 | 2008-10-13 10:40:07 +0100 | [diff] [blame] | 960 | tty_port_tty_set(&portp->port, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | |
| 962 | if (portp->openwaitcnt) { |
| 963 | if (portp->close_delay) |
| 964 | msleep_interruptible(jiffies_to_msecs(portp->close_delay)); |
Alan Cox | f8ae476 | 2008-07-16 21:56:37 +0100 | [diff] [blame] | 965 | wake_up_interruptible(&portp->port.open_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | } |
| 967 | |
Alan Cox | f8ae476 | 2008-07-16 21:56:37 +0100 | [diff] [blame] | 968 | portp->port.flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING); |
| 969 | wake_up_interruptible(&portp->port.close_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | /*****************************************************************************/ |
| 973 | |
| 974 | /* |
| 975 | * Write routine. Take data and stuff it in to the TX ring queue. |
| 976 | * If transmit interrupts are not running then start them. |
| 977 | */ |
| 978 | |
| 979 | static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count) |
| 980 | { |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 981 | struct stlport *portp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | unsigned int len, stlen; |
| 983 | unsigned char *chbuf; |
| 984 | char *head, *tail; |
| 985 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 986 | pr_debug("stl_write(tty=%p,buf=%p,count=%d)\n", tty, buf, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | portp = tty->driver_data; |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 989 | if (portp == NULL) |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 990 | return 0; |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 991 | if (portp->tx.buf == NULL) |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 992 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | |
| 994 | /* |
| 995 | * If copying direct from user space we must cater for page faults, |
| 996 | * causing us to "sleep" here for a while. To handle this copy in all |
| 997 | * the data we need now, into a local buffer. Then when we got it all |
| 998 | * copy it into the TX buffer. |
| 999 | */ |
| 1000 | chbuf = (unsigned char *) buf; |
| 1001 | |
| 1002 | head = portp->tx.head; |
| 1003 | tail = portp->tx.tail; |
| 1004 | if (head >= tail) { |
| 1005 | len = STL_TXBUFSIZE - (head - tail) - 1; |
| 1006 | stlen = STL_TXBUFSIZE - (head - portp->tx.buf); |
| 1007 | } else { |
| 1008 | len = tail - head - 1; |
| 1009 | stlen = len; |
| 1010 | } |
| 1011 | |
Jiri Slaby | 843b568 | 2006-12-08 02:39:12 -0800 | [diff] [blame] | 1012 | len = min(len, (unsigned int)count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | count = 0; |
| 1014 | while (len > 0) { |
Jiri Slaby | 843b568 | 2006-12-08 02:39:12 -0800 | [diff] [blame] | 1015 | stlen = min(len, stlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | memcpy(head, chbuf, stlen); |
| 1017 | len -= stlen; |
| 1018 | chbuf += stlen; |
| 1019 | count += stlen; |
| 1020 | head += stlen; |
| 1021 | if (head >= (portp->tx.buf + STL_TXBUFSIZE)) { |
| 1022 | head = portp->tx.buf; |
| 1023 | stlen = tail - head; |
| 1024 | } |
| 1025 | } |
| 1026 | portp->tx.head = head; |
| 1027 | |
| 1028 | clear_bit(ASYI_TXLOW, &portp->istate); |
| 1029 | stl_startrxtx(portp, -1, 1); |
| 1030 | |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 1031 | return count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | /*****************************************************************************/ |
| 1035 | |
David Howells | 4a56122 | 2008-07-22 11:18:43 +0100 | [diff] [blame] | 1036 | static int stl_putchar(struct tty_struct *tty, unsigned char ch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | { |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 1038 | struct stlport *portp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | unsigned int len; |
| 1040 | char *head, *tail; |
| 1041 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 1042 | pr_debug("stl_putchar(tty=%p,ch=%x)\n", tty, ch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | portp = tty->driver_data; |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 1045 | if (portp == NULL) |
David Howells | 4a56122 | 2008-07-22 11:18:43 +0100 | [diff] [blame] | 1046 | return -EINVAL; |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 1047 | if (portp->tx.buf == NULL) |
David Howells | 4a56122 | 2008-07-22 11:18:43 +0100 | [diff] [blame] | 1048 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | |
| 1050 | head = portp->tx.head; |
| 1051 | tail = portp->tx.tail; |
| 1052 | |
| 1053 | len = (head >= tail) ? (STL_TXBUFSIZE - (head - tail)) : (tail - head); |
| 1054 | len--; |
| 1055 | |
| 1056 | if (len > 0) { |
| 1057 | *head++ = ch; |
| 1058 | if (head >= (portp->tx.buf + STL_TXBUFSIZE)) |
| 1059 | head = portp->tx.buf; |
| 1060 | } |
| 1061 | portp->tx.head = head; |
David Howells | 4a56122 | 2008-07-22 11:18:43 +0100 | [diff] [blame] | 1062 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1063 | } |
| 1064 | |
| 1065 | /*****************************************************************************/ |
| 1066 | |
| 1067 | /* |
| 1068 | * If there are any characters in the buffer then make sure that TX |
| 1069 | * interrupts are on and get'em out. Normally used after the putchar |
| 1070 | * routine has been called. |
| 1071 | */ |
| 1072 | |
| 1073 | static void stl_flushchars(struct tty_struct *tty) |
| 1074 | { |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 1075 | struct stlport *portp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 1077 | pr_debug("stl_flushchars(tty=%p)\n", tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | portp = tty->driver_data; |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 1080 | if (portp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | return; |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 1082 | if (portp->tx.buf == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | return; |
| 1084 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | stl_startrxtx(portp, -1, 1); |
| 1086 | } |
| 1087 | |
| 1088 | /*****************************************************************************/ |
| 1089 | |
| 1090 | static int stl_writeroom(struct tty_struct *tty) |
| 1091 | { |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 1092 | struct stlport *portp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | char *head, *tail; |
| 1094 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 1095 | pr_debug("stl_writeroom(tty=%p)\n", tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | portp = tty->driver_data; |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 1098 | if (portp == NULL) |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 1099 | return 0; |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 1100 | if (portp->tx.buf == NULL) |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 1101 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | |
| 1103 | head = portp->tx.head; |
| 1104 | tail = portp->tx.tail; |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 1105 | return (head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) : (tail - head - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | } |
| 1107 | |
| 1108 | /*****************************************************************************/ |
| 1109 | |
| 1110 | /* |
| 1111 | * Return number of chars in the TX buffer. Normally we would just |
| 1112 | * calculate the number of chars in the buffer and return that, but if |
| 1113 | * the buffer is empty and TX interrupts are still on then we return |
| 1114 | * that the buffer still has 1 char in it. This way whoever called us |
| 1115 | * will not think that ALL chars have drained - since the UART still |
| 1116 | * must have some chars in it (we are busy after all). |
| 1117 | */ |
| 1118 | |
| 1119 | static int stl_charsinbuffer(struct tty_struct *tty) |
| 1120 | { |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 1121 | struct stlport *portp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | unsigned int size; |
| 1123 | char *head, *tail; |
| 1124 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 1125 | pr_debug("stl_charsinbuffer(tty=%p)\n", tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1127 | portp = tty->driver_data; |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 1128 | if (portp == NULL) |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 1129 | return 0; |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 1130 | if (portp->tx.buf == NULL) |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 1131 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | |
| 1133 | head = portp->tx.head; |
| 1134 | tail = portp->tx.tail; |
| 1135 | size = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head)); |
| 1136 | if ((size == 0) && test_bit(ASYI_TXBUSY, &portp->istate)) |
| 1137 | size = 1; |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 1138 | return size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1139 | } |
| 1140 | |
| 1141 | /*****************************************************************************/ |
| 1142 | |
| 1143 | /* |
| 1144 | * Generate the serial struct info. |
| 1145 | */ |
| 1146 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 1147 | static int stl_getserial(struct stlport *portp, struct serial_struct __user *sp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1148 | { |
| 1149 | struct serial_struct sio; |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 1150 | struct stlbrd *brdp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 1152 | pr_debug("stl_getserial(portp=%p,sp=%p)\n", portp, sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1153 | |
| 1154 | memset(&sio, 0, sizeof(struct serial_struct)); |
| 1155 | sio.line = portp->portnr; |
| 1156 | sio.port = portp->ioaddr; |
Alan Cox | f8ae476 | 2008-07-16 21:56:37 +0100 | [diff] [blame] | 1157 | sio.flags = portp->port.flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1158 | sio.baud_base = portp->baud_base; |
| 1159 | sio.close_delay = portp->close_delay; |
| 1160 | sio.closing_wait = portp->closing_wait; |
| 1161 | sio.custom_divisor = portp->custom_divisor; |
| 1162 | sio.hub6 = 0; |
| 1163 | if (portp->uartp == &stl_cd1400uart) { |
| 1164 | sio.type = PORT_CIRRUS; |
| 1165 | sio.xmit_fifo_size = CD1400_TXFIFOSIZE; |
| 1166 | } else { |
| 1167 | sio.type = PORT_UNKNOWN; |
| 1168 | sio.xmit_fifo_size = SC26198_TXFIFOSIZE; |
| 1169 | } |
| 1170 | |
| 1171 | brdp = stl_brds[portp->brdnr]; |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 1172 | if (brdp != NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1173 | sio.irq = brdp->irq; |
| 1174 | |
| 1175 | return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ? -EFAULT : 0; |
| 1176 | } |
| 1177 | |
| 1178 | /*****************************************************************************/ |
| 1179 | |
| 1180 | /* |
| 1181 | * Set port according to the serial struct info. |
| 1182 | * At this point we do not do any auto-configure stuff, so we will |
| 1183 | * just quietly ignore any requests to change irq, etc. |
| 1184 | */ |
| 1185 | |
Alan Cox | d18a750 | 2008-10-13 10:40:07 +0100 | [diff] [blame] | 1186 | static int stl_setserial(struct tty_struct *tty, struct serial_struct __user *sp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1187 | { |
Alan Cox | d18a750 | 2008-10-13 10:40:07 +0100 | [diff] [blame] | 1188 | struct stlport * portp = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | struct serial_struct sio; |
| 1190 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 1191 | pr_debug("stl_setserial(portp=%p,sp=%p)\n", portp, sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1192 | |
| 1193 | if (copy_from_user(&sio, sp, sizeof(struct serial_struct))) |
| 1194 | return -EFAULT; |
| 1195 | if (!capable(CAP_SYS_ADMIN)) { |
| 1196 | if ((sio.baud_base != portp->baud_base) || |
| 1197 | (sio.close_delay != portp->close_delay) || |
| 1198 | ((sio.flags & ~ASYNC_USR_MASK) != |
Alan Cox | f8ae476 | 2008-07-16 21:56:37 +0100 | [diff] [blame] | 1199 | (portp->port.flags & ~ASYNC_USR_MASK))) |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 1200 | return -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | } |
| 1202 | |
Alan Cox | f8ae476 | 2008-07-16 21:56:37 +0100 | [diff] [blame] | 1203 | portp->port.flags = (portp->port.flags & ~ASYNC_USR_MASK) | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1204 | (sio.flags & ASYNC_USR_MASK); |
| 1205 | portp->baud_base = sio.baud_base; |
| 1206 | portp->close_delay = sio.close_delay; |
| 1207 | portp->closing_wait = sio.closing_wait; |
| 1208 | portp->custom_divisor = sio.custom_divisor; |
Alan Cox | d18a750 | 2008-10-13 10:40:07 +0100 | [diff] [blame] | 1209 | stl_setport(portp, tty->termios); |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 1210 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | } |
| 1212 | |
| 1213 | /*****************************************************************************/ |
| 1214 | |
| 1215 | static int stl_tiocmget(struct tty_struct *tty, struct file *file) |
| 1216 | { |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 1217 | struct stlport *portp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1219 | portp = tty->driver_data; |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 1220 | if (portp == NULL) |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 1221 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1222 | if (tty->flags & (1 << TTY_IO_ERROR)) |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 1223 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1224 | |
| 1225 | return stl_getsignals(portp); |
| 1226 | } |
| 1227 | |
| 1228 | static int stl_tiocmset(struct tty_struct *tty, struct file *file, |
| 1229 | unsigned int set, unsigned int clear) |
| 1230 | { |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 1231 | struct stlport *portp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | int rts = -1, dtr = -1; |
| 1233 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1234 | portp = tty->driver_data; |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 1235 | if (portp == NULL) |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 1236 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1237 | if (tty->flags & (1 << TTY_IO_ERROR)) |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 1238 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1239 | |
| 1240 | if (set & TIOCM_RTS) |
| 1241 | rts = 1; |
| 1242 | if (set & TIOCM_DTR) |
| 1243 | dtr = 1; |
| 1244 | if (clear & TIOCM_RTS) |
| 1245 | rts = 0; |
| 1246 | if (clear & TIOCM_DTR) |
| 1247 | dtr = 0; |
| 1248 | |
| 1249 | stl_setsignals(portp, dtr, rts); |
| 1250 | return 0; |
| 1251 | } |
| 1252 | |
| 1253 | static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg) |
| 1254 | { |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 1255 | struct stlport *portp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1256 | int rc; |
| 1257 | void __user *argp = (void __user *)arg; |
| 1258 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 1259 | pr_debug("stl_ioctl(tty=%p,file=%p,cmd=%x,arg=%lx)\n", tty, file, cmd, |
| 1260 | arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | portp = tty->driver_data; |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 1263 | if (portp == NULL) |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 1264 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | |
| 1266 | if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) && |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 1267 | (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | if (tty->flags & (1 << TTY_IO_ERROR)) |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 1269 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | |
| 1271 | rc = 0; |
| 1272 | |
Alan Cox | f433c65 | 2008-04-30 00:53:23 -0700 | [diff] [blame] | 1273 | lock_kernel(); |
| 1274 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | switch (cmd) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1276 | case TIOCGSERIAL: |
| 1277 | rc = stl_getserial(portp, argp); |
| 1278 | break; |
| 1279 | case TIOCSSERIAL: |
Alan Cox | d18a750 | 2008-10-13 10:40:07 +0100 | [diff] [blame] | 1280 | rc = stl_setserial(tty, argp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | break; |
| 1282 | case COM_GETPORTSTATS: |
Alan Cox | d18a750 | 2008-10-13 10:40:07 +0100 | [diff] [blame] | 1283 | rc = stl_getportstats(tty, portp, argp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1284 | break; |
| 1285 | case COM_CLRPORTSTATS: |
| 1286 | rc = stl_clrportstats(portp, argp); |
| 1287 | break; |
| 1288 | case TIOCSERCONFIG: |
| 1289 | case TIOCSERGWILD: |
| 1290 | case TIOCSERSWILD: |
| 1291 | case TIOCSERGETLSR: |
| 1292 | case TIOCSERGSTRUCT: |
| 1293 | case TIOCSERGETMULTI: |
| 1294 | case TIOCSERSETMULTI: |
| 1295 | default: |
| 1296 | rc = -ENOIOCTLCMD; |
| 1297 | break; |
| 1298 | } |
Alan Cox | f433c65 | 2008-04-30 00:53:23 -0700 | [diff] [blame] | 1299 | unlock_kernel(); |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 1300 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | } |
| 1302 | |
| 1303 | /*****************************************************************************/ |
| 1304 | |
Jiri Slaby | 96b066b | 2006-12-08 02:38:42 -0800 | [diff] [blame] | 1305 | /* |
| 1306 | * Start the transmitter again. Just turn TX interrupts back on. |
| 1307 | */ |
| 1308 | |
| 1309 | static void stl_start(struct tty_struct *tty) |
| 1310 | { |
| 1311 | struct stlport *portp; |
| 1312 | |
| 1313 | pr_debug("stl_start(tty=%p)\n", tty); |
| 1314 | |
Jiri Slaby | 96b066b | 2006-12-08 02:38:42 -0800 | [diff] [blame] | 1315 | portp = tty->driver_data; |
| 1316 | if (portp == NULL) |
| 1317 | return; |
| 1318 | stl_startrxtx(portp, -1, 1); |
| 1319 | } |
| 1320 | |
| 1321 | /*****************************************************************************/ |
| 1322 | |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 1323 | static void stl_settermios(struct tty_struct *tty, struct ktermios *old) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1324 | { |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 1325 | struct stlport *portp; |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 1326 | struct ktermios *tiosp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 1328 | pr_debug("stl_settermios(tty=%p,old=%p)\n", tty, old); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1329 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | portp = tty->driver_data; |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 1331 | if (portp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1332 | return; |
| 1333 | |
| 1334 | tiosp = tty->termios; |
| 1335 | if ((tiosp->c_cflag == old->c_cflag) && |
| 1336 | (tiosp->c_iflag == old->c_iflag)) |
| 1337 | return; |
| 1338 | |
| 1339 | stl_setport(portp, tiosp); |
| 1340 | stl_setsignals(portp, ((tiosp->c_cflag & (CBAUD & ~CBAUDEX)) ? 1 : 0), |
| 1341 | -1); |
| 1342 | if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0)) { |
| 1343 | tty->hw_stopped = 0; |
| 1344 | stl_start(tty); |
| 1345 | } |
| 1346 | if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL)) |
Alan Cox | f8ae476 | 2008-07-16 21:56:37 +0100 | [diff] [blame] | 1347 | wake_up_interruptible(&portp->port.open_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1348 | } |
| 1349 | |
| 1350 | /*****************************************************************************/ |
| 1351 | |
| 1352 | /* |
| 1353 | * Attempt to flow control who ever is sending us data. Based on termios |
| 1354 | * settings use software or/and hardware flow control. |
| 1355 | */ |
| 1356 | |
| 1357 | static void stl_throttle(struct tty_struct *tty) |
| 1358 | { |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 1359 | struct stlport *portp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 1361 | pr_debug("stl_throttle(tty=%p)\n", tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1362 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1363 | portp = tty->driver_data; |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 1364 | if (portp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1365 | return; |
| 1366 | stl_flowctrl(portp, 0); |
| 1367 | } |
| 1368 | |
| 1369 | /*****************************************************************************/ |
| 1370 | |
| 1371 | /* |
| 1372 | * Unflow control the device sending us data... |
| 1373 | */ |
| 1374 | |
| 1375 | static void stl_unthrottle(struct tty_struct *tty) |
| 1376 | { |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 1377 | struct stlport *portp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1378 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 1379 | pr_debug("stl_unthrottle(tty=%p)\n", tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1380 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1381 | portp = tty->driver_data; |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 1382 | if (portp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1383 | return; |
| 1384 | stl_flowctrl(portp, 1); |
| 1385 | } |
| 1386 | |
| 1387 | /*****************************************************************************/ |
| 1388 | |
| 1389 | /* |
| 1390 | * Stop the transmitter. Basically to do this we will just turn TX |
| 1391 | * interrupts off. |
| 1392 | */ |
| 1393 | |
| 1394 | static void stl_stop(struct tty_struct *tty) |
| 1395 | { |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 1396 | struct stlport *portp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1397 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 1398 | pr_debug("stl_stop(tty=%p)\n", tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1399 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1400 | portp = tty->driver_data; |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 1401 | if (portp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | return; |
| 1403 | stl_startrxtx(portp, -1, 0); |
| 1404 | } |
| 1405 | |
| 1406 | /*****************************************************************************/ |
| 1407 | |
| 1408 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1409 | * Hangup this port. This is pretty much like closing the port, only |
| 1410 | * a little more brutal. No waiting for data to drain. Shutdown the |
| 1411 | * port and maybe drop signals. |
| 1412 | */ |
| 1413 | |
| 1414 | static void stl_hangup(struct tty_struct *tty) |
| 1415 | { |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 1416 | struct stlport *portp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1417 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 1418 | pr_debug("stl_hangup(tty=%p)\n", tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1419 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1420 | portp = tty->driver_data; |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 1421 | if (portp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | return; |
| 1423 | |
Alan Cox | f8ae476 | 2008-07-16 21:56:37 +0100 | [diff] [blame] | 1424 | portp->port.flags &= ~ASYNC_INITIALIZED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1425 | stl_disableintrs(portp); |
| 1426 | if (tty->termios->c_cflag & HUPCL) |
| 1427 | stl_setsignals(portp, 0, 0); |
| 1428 | stl_enablerxtx(portp, 0, 0); |
| 1429 | stl_flushbuffer(tty); |
| 1430 | portp->istate = 0; |
| 1431 | set_bit(TTY_IO_ERROR, &tty->flags); |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 1432 | if (portp->tx.buf != NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1433 | kfree(portp->tx.buf); |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 1434 | portp->tx.buf = NULL; |
| 1435 | portp->tx.head = NULL; |
| 1436 | portp->tx.tail = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1437 | } |
Alan Cox | d18a750 | 2008-10-13 10:40:07 +0100 | [diff] [blame] | 1438 | tty_port_tty_set(&portp->port, NULL); |
Alan Cox | f8ae476 | 2008-07-16 21:56:37 +0100 | [diff] [blame] | 1439 | portp->port.flags &= ~ASYNC_NORMAL_ACTIVE; |
| 1440 | portp->port.count = 0; |
| 1441 | wake_up_interruptible(&portp->port.open_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1442 | } |
| 1443 | |
| 1444 | /*****************************************************************************/ |
| 1445 | |
David Howells | 4a56122 | 2008-07-22 11:18:43 +0100 | [diff] [blame] | 1446 | static int stl_breakctl(struct tty_struct *tty, int state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1447 | { |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 1448 | struct stlport *portp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1449 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 1450 | pr_debug("stl_breakctl(tty=%p,state=%d)\n", tty, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1452 | portp = tty->driver_data; |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 1453 | if (portp == NULL) |
David Howells | 4a56122 | 2008-07-22 11:18:43 +0100 | [diff] [blame] | 1454 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1455 | |
| 1456 | stl_sendbreak(portp, ((state == -1) ? 1 : 2)); |
David Howells | 4a56122 | 2008-07-22 11:18:43 +0100 | [diff] [blame] | 1457 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1458 | } |
| 1459 | |
| 1460 | /*****************************************************************************/ |
| 1461 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1462 | static void stl_sendxchar(struct tty_struct *tty, char ch) |
| 1463 | { |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 1464 | struct stlport *portp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1465 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 1466 | pr_debug("stl_sendxchar(tty=%p,ch=%x)\n", tty, ch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1467 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1468 | portp = tty->driver_data; |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 1469 | if (portp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1470 | return; |
| 1471 | |
| 1472 | if (ch == STOP_CHAR(tty)) |
| 1473 | stl_sendflow(portp, 0); |
| 1474 | else if (ch == START_CHAR(tty)) |
| 1475 | stl_sendflow(portp, 1); |
| 1476 | else |
| 1477 | stl_putchar(tty, ch); |
| 1478 | } |
| 1479 | |
| 1480 | /*****************************************************************************/ |
| 1481 | |
| 1482 | #define MAXLINE 80 |
| 1483 | |
| 1484 | /* |
| 1485 | * Format info for a specified port. The line is deliberately limited |
| 1486 | * to 80 characters. (If it is too long it will be truncated, if too |
| 1487 | * short then padded with spaces). |
| 1488 | */ |
| 1489 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 1490 | static int stl_portinfo(struct stlport *portp, int portnr, char *pos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1491 | { |
| 1492 | char *sp; |
| 1493 | int sigs, cnt; |
| 1494 | |
| 1495 | sp = pos; |
| 1496 | sp += sprintf(sp, "%d: uart:%s tx:%d rx:%d", |
| 1497 | portnr, (portp->hwid == 1) ? "SC26198" : "CD1400", |
| 1498 | (int) portp->stats.txtotal, (int) portp->stats.rxtotal); |
| 1499 | |
| 1500 | if (portp->stats.rxframing) |
| 1501 | sp += sprintf(sp, " fe:%d", (int) portp->stats.rxframing); |
| 1502 | if (portp->stats.rxparity) |
| 1503 | sp += sprintf(sp, " pe:%d", (int) portp->stats.rxparity); |
| 1504 | if (portp->stats.rxbreaks) |
| 1505 | sp += sprintf(sp, " brk:%d", (int) portp->stats.rxbreaks); |
| 1506 | if (portp->stats.rxoverrun) |
| 1507 | sp += sprintf(sp, " oe:%d", (int) portp->stats.rxoverrun); |
| 1508 | |
| 1509 | sigs = stl_getsignals(portp); |
| 1510 | cnt = sprintf(sp, "%s%s%s%s%s ", |
| 1511 | (sigs & TIOCM_RTS) ? "|RTS" : "", |
| 1512 | (sigs & TIOCM_CTS) ? "|CTS" : "", |
| 1513 | (sigs & TIOCM_DTR) ? "|DTR" : "", |
| 1514 | (sigs & TIOCM_CD) ? "|DCD" : "", |
| 1515 | (sigs & TIOCM_DSR) ? "|DSR" : ""); |
| 1516 | *sp = ' '; |
| 1517 | sp += cnt; |
| 1518 | |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 1519 | for (cnt = sp - pos; cnt < (MAXLINE - 1); cnt++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1520 | *sp++ = ' '; |
| 1521 | if (cnt >= MAXLINE) |
| 1522 | pos[(MAXLINE - 2)] = '+'; |
| 1523 | pos[(MAXLINE - 1)] = '\n'; |
| 1524 | |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 1525 | return MAXLINE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1526 | } |
| 1527 | |
| 1528 | /*****************************************************************************/ |
| 1529 | |
| 1530 | /* |
| 1531 | * Port info, read from the /proc file system. |
| 1532 | */ |
| 1533 | |
| 1534 | static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data) |
| 1535 | { |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 1536 | struct stlbrd *brdp; |
| 1537 | struct stlpanel *panelp; |
| 1538 | struct stlport *portp; |
Jiri Slaby | 6b2c945 | 2006-12-08 02:39:15 -0800 | [diff] [blame] | 1539 | unsigned int brdnr, panelnr, portnr; |
| 1540 | int totalport, curoff, maxoff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1541 | char *pos; |
| 1542 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 1543 | pr_debug("stl_readproc(page=%p,start=%p,off=%lx,count=%d,eof=%p," |
| 1544 | "data=%p\n", page, start, off, count, eof, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1545 | |
| 1546 | pos = page; |
| 1547 | totalport = 0; |
| 1548 | curoff = 0; |
| 1549 | |
| 1550 | if (off == 0) { |
| 1551 | pos += sprintf(pos, "%s: version %s", stl_drvtitle, |
| 1552 | stl_drvversion); |
| 1553 | while (pos < (page + MAXLINE - 1)) |
| 1554 | *pos++ = ' '; |
| 1555 | *pos++ = '\n'; |
| 1556 | } |
| 1557 | curoff = MAXLINE; |
| 1558 | |
| 1559 | /* |
| 1560 | * We scan through for each board, panel and port. The offset is |
| 1561 | * calculated on the fly, and irrelevant ports are skipped. |
| 1562 | */ |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 1563 | for (brdnr = 0; brdnr < stl_nrbrds; brdnr++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1564 | brdp = stl_brds[brdnr]; |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 1565 | if (brdp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1566 | continue; |
| 1567 | if (brdp->state == 0) |
| 1568 | continue; |
| 1569 | |
| 1570 | maxoff = curoff + (brdp->nrports * MAXLINE); |
| 1571 | if (off >= maxoff) { |
| 1572 | curoff = maxoff; |
| 1573 | continue; |
| 1574 | } |
| 1575 | |
| 1576 | totalport = brdnr * STL_MAXPORTS; |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 1577 | for (panelnr = 0; panelnr < brdp->nrpanels; panelnr++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1578 | panelp = brdp->panels[panelnr]; |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 1579 | if (panelp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1580 | continue; |
| 1581 | |
| 1582 | maxoff = curoff + (panelp->nrports * MAXLINE); |
| 1583 | if (off >= maxoff) { |
| 1584 | curoff = maxoff; |
| 1585 | totalport += panelp->nrports; |
| 1586 | continue; |
| 1587 | } |
| 1588 | |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 1589 | for (portnr = 0; portnr < panelp->nrports; portnr++, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1590 | totalport++) { |
| 1591 | portp = panelp->ports[portnr]; |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 1592 | if (portp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 | continue; |
| 1594 | if (off >= (curoff += MAXLINE)) |
| 1595 | continue; |
| 1596 | if ((pos - page + MAXLINE) > count) |
| 1597 | goto stl_readdone; |
| 1598 | pos += stl_portinfo(portp, totalport, pos); |
| 1599 | } |
| 1600 | } |
| 1601 | } |
| 1602 | |
| 1603 | *eof = 1; |
| 1604 | |
| 1605 | stl_readdone: |
| 1606 | *start = page; |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 1607 | return pos - page; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1608 | } |
| 1609 | |
| 1610 | /*****************************************************************************/ |
| 1611 | |
| 1612 | /* |
| 1613 | * All board interrupts are vectored through here first. This code then |
| 1614 | * calls off to the approrpriate board interrupt handlers. |
| 1615 | */ |
| 1616 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1617 | static irqreturn_t stl_intr(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1618 | { |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 1619 | struct stlbrd *brdp = dev_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1620 | |
Jeff Garzik | a6f97b2 | 2007-10-31 05:20:49 -0400 | [diff] [blame] | 1621 | pr_debug("stl_intr(brdp=%p,irq=%d)\n", brdp, brdp->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1622 | |
| 1623 | return IRQ_RETVAL((* brdp->isr)(brdp)); |
| 1624 | } |
| 1625 | |
| 1626 | /*****************************************************************************/ |
| 1627 | |
| 1628 | /* |
| 1629 | * Interrupt service routine for EasyIO board types. |
| 1630 | */ |
| 1631 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 1632 | static int stl_eiointr(struct stlbrd *brdp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1633 | { |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 1634 | struct stlpanel *panelp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1635 | unsigned int iobase; |
| 1636 | int handled = 0; |
| 1637 | |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 1638 | spin_lock(&brd_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1639 | panelp = brdp->panels[0]; |
| 1640 | iobase = panelp->iobase; |
| 1641 | while (inb(brdp->iostatus) & EIO_INTRPEND) { |
| 1642 | handled = 1; |
| 1643 | (* panelp->isr)(panelp, iobase); |
| 1644 | } |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 1645 | spin_unlock(&brd_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1646 | return handled; |
| 1647 | } |
| 1648 | |
| 1649 | /*****************************************************************************/ |
| 1650 | |
| 1651 | /* |
| 1652 | * Interrupt service routine for ECH-AT board types. |
| 1653 | */ |
| 1654 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 1655 | static int stl_echatintr(struct stlbrd *brdp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1656 | { |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 1657 | struct stlpanel *panelp; |
Jiri Slaby | 6b2c945 | 2006-12-08 02:39:15 -0800 | [diff] [blame] | 1658 | unsigned int ioaddr, bnknr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1659 | int handled = 0; |
| 1660 | |
| 1661 | outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl); |
| 1662 | |
| 1663 | while (inb(brdp->iostatus) & ECH_INTRPEND) { |
| 1664 | handled = 1; |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 1665 | for (bnknr = 0; bnknr < brdp->nrbnks; bnknr++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1666 | ioaddr = brdp->bnkstataddr[bnknr]; |
| 1667 | if (inb(ioaddr) & ECH_PNLINTRPEND) { |
| 1668 | panelp = brdp->bnk2panel[bnknr]; |
| 1669 | (* panelp->isr)(panelp, (ioaddr & 0xfffc)); |
| 1670 | } |
| 1671 | } |
| 1672 | } |
| 1673 | |
| 1674 | outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl); |
| 1675 | |
| 1676 | return handled; |
| 1677 | } |
| 1678 | |
| 1679 | /*****************************************************************************/ |
| 1680 | |
| 1681 | /* |
| 1682 | * Interrupt service routine for ECH-MCA board types. |
| 1683 | */ |
| 1684 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 1685 | static int stl_echmcaintr(struct stlbrd *brdp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1686 | { |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 1687 | struct stlpanel *panelp; |
Jiri Slaby | 6b2c945 | 2006-12-08 02:39:15 -0800 | [diff] [blame] | 1688 | unsigned int ioaddr, bnknr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1689 | int handled = 0; |
| 1690 | |
| 1691 | while (inb(brdp->iostatus) & ECH_INTRPEND) { |
| 1692 | handled = 1; |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 1693 | for (bnknr = 0; bnknr < brdp->nrbnks; bnknr++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1694 | ioaddr = brdp->bnkstataddr[bnknr]; |
| 1695 | if (inb(ioaddr) & ECH_PNLINTRPEND) { |
| 1696 | panelp = brdp->bnk2panel[bnknr]; |
| 1697 | (* panelp->isr)(panelp, (ioaddr & 0xfffc)); |
| 1698 | } |
| 1699 | } |
| 1700 | } |
| 1701 | return handled; |
| 1702 | } |
| 1703 | |
| 1704 | /*****************************************************************************/ |
| 1705 | |
| 1706 | /* |
| 1707 | * Interrupt service routine for ECH-PCI board types. |
| 1708 | */ |
| 1709 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 1710 | static int stl_echpciintr(struct stlbrd *brdp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1711 | { |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 1712 | struct stlpanel *panelp; |
Jiri Slaby | 6b2c945 | 2006-12-08 02:39:15 -0800 | [diff] [blame] | 1713 | unsigned int ioaddr, bnknr, recheck; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1714 | int handled = 0; |
| 1715 | |
| 1716 | while (1) { |
| 1717 | recheck = 0; |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 1718 | for (bnknr = 0; bnknr < brdp->nrbnks; bnknr++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1719 | outb(brdp->bnkpageaddr[bnknr], brdp->ioctrl); |
| 1720 | ioaddr = brdp->bnkstataddr[bnknr]; |
| 1721 | if (inb(ioaddr) & ECH_PNLINTRPEND) { |
| 1722 | panelp = brdp->bnk2panel[bnknr]; |
| 1723 | (* panelp->isr)(panelp, (ioaddr & 0xfffc)); |
| 1724 | recheck++; |
| 1725 | handled = 1; |
| 1726 | } |
| 1727 | } |
| 1728 | if (! recheck) |
| 1729 | break; |
| 1730 | } |
| 1731 | return handled; |
| 1732 | } |
| 1733 | |
| 1734 | /*****************************************************************************/ |
| 1735 | |
| 1736 | /* |
| 1737 | * Interrupt service routine for ECH-8/64-PCI board types. |
| 1738 | */ |
| 1739 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 1740 | static int stl_echpci64intr(struct stlbrd *brdp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1741 | { |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 1742 | struct stlpanel *panelp; |
Jiri Slaby | 6b2c945 | 2006-12-08 02:39:15 -0800 | [diff] [blame] | 1743 | unsigned int ioaddr, bnknr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1744 | int handled = 0; |
| 1745 | |
| 1746 | while (inb(brdp->ioctrl) & 0x1) { |
| 1747 | handled = 1; |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 1748 | for (bnknr = 0; bnknr < brdp->nrbnks; bnknr++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1749 | ioaddr = brdp->bnkstataddr[bnknr]; |
| 1750 | if (inb(ioaddr) & ECH_PNLINTRPEND) { |
| 1751 | panelp = brdp->bnk2panel[bnknr]; |
| 1752 | (* panelp->isr)(panelp, (ioaddr & 0xfffc)); |
| 1753 | } |
| 1754 | } |
| 1755 | } |
| 1756 | |
| 1757 | return handled; |
| 1758 | } |
| 1759 | |
| 1760 | /*****************************************************************************/ |
| 1761 | |
| 1762 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1763 | * Initialize all the ports on a panel. |
| 1764 | */ |
| 1765 | |
Jiri Slaby | 705c186 | 2006-12-08 02:39:11 -0800 | [diff] [blame] | 1766 | static int __devinit stl_initports(struct stlbrd *brdp, struct stlpanel *panelp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1767 | { |
Jiri Slaby | 6b2c945 | 2006-12-08 02:39:15 -0800 | [diff] [blame] | 1768 | struct stlport *portp; |
| 1769 | unsigned int i; |
| 1770 | int chipmask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1771 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 1772 | pr_debug("stl_initports(brdp=%p,panelp=%p)\n", brdp, panelp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1773 | |
| 1774 | chipmask = stl_panelinit(brdp, panelp); |
| 1775 | |
| 1776 | /* |
| 1777 | * All UART's are initialized (if found!). Now go through and setup |
| 1778 | * each ports data structures. |
| 1779 | */ |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 1780 | for (i = 0; i < panelp->nrports; i++) { |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 1781 | portp = kzalloc(sizeof(struct stlport), GFP_KERNEL); |
Tobias Klauser | b0b4ed7 | 2006-03-31 02:30:56 -0800 | [diff] [blame] | 1782 | if (!portp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1783 | printk("STALLION: failed to allocate memory " |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 1784 | "(size=%Zd)\n", sizeof(struct stlport)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1785 | break; |
| 1786 | } |
Alan Cox | d18a750 | 2008-10-13 10:40:07 +0100 | [diff] [blame] | 1787 | tty_port_init(&portp->port); |
Alan Cox | 31f3593 | 2009-01-02 13:45:05 +0000 | [diff] [blame^] | 1788 | portp->port.ops = &stl_port_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1789 | portp->magic = STL_PORTMAGIC; |
| 1790 | portp->portnr = i; |
| 1791 | portp->brdnr = panelp->brdnr; |
| 1792 | portp->panelnr = panelp->panelnr; |
| 1793 | portp->uartp = panelp->uartp; |
| 1794 | portp->clk = brdp->clk; |
| 1795 | portp->baud_base = STL_BAUDBASE; |
| 1796 | portp->close_delay = STL_CLOSEDELAY; |
| 1797 | portp->closing_wait = 30 * HZ; |
Alan Cox | f8ae476 | 2008-07-16 21:56:37 +0100 | [diff] [blame] | 1798 | init_waitqueue_head(&portp->port.open_wait); |
| 1799 | init_waitqueue_head(&portp->port.close_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1800 | portp->stats.brd = portp->brdnr; |
| 1801 | portp->stats.panel = portp->panelnr; |
| 1802 | portp->stats.port = portp->portnr; |
| 1803 | panelp->ports[i] = portp; |
| 1804 | stl_portinit(brdp, panelp, portp); |
| 1805 | } |
| 1806 | |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 1807 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1808 | } |
| 1809 | |
Jiri Slaby | 3b85b34 | 2006-12-08 02:39:10 -0800 | [diff] [blame] | 1810 | static void stl_cleanup_panels(struct stlbrd *brdp) |
| 1811 | { |
| 1812 | struct stlpanel *panelp; |
| 1813 | struct stlport *portp; |
| 1814 | unsigned int j, k; |
Alan Cox | d18a750 | 2008-10-13 10:40:07 +0100 | [diff] [blame] | 1815 | struct tty_struct *tty; |
Jiri Slaby | 3b85b34 | 2006-12-08 02:39:10 -0800 | [diff] [blame] | 1816 | |
| 1817 | for (j = 0; j < STL_MAXPANELS; j++) { |
| 1818 | panelp = brdp->panels[j]; |
| 1819 | if (panelp == NULL) |
| 1820 | continue; |
| 1821 | for (k = 0; k < STL_PORTSPERPANEL; k++) { |
| 1822 | portp = panelp->ports[k]; |
| 1823 | if (portp == NULL) |
| 1824 | continue; |
Alan Cox | d18a750 | 2008-10-13 10:40:07 +0100 | [diff] [blame] | 1825 | tty = tty_port_tty_get(&portp->port); |
| 1826 | if (tty != NULL) { |
| 1827 | stl_hangup(tty); |
| 1828 | tty_kref_put(tty); |
| 1829 | } |
Jiri Slaby | 3b85b34 | 2006-12-08 02:39:10 -0800 | [diff] [blame] | 1830 | kfree(portp->tx.buf); |
| 1831 | kfree(portp); |
| 1832 | } |
| 1833 | kfree(panelp); |
| 1834 | } |
| 1835 | } |
| 1836 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 | /*****************************************************************************/ |
| 1838 | |
| 1839 | /* |
| 1840 | * Try to find and initialize an EasyIO board. |
| 1841 | */ |
| 1842 | |
Jiri Slaby | 705c186 | 2006-12-08 02:39:11 -0800 | [diff] [blame] | 1843 | static int __devinit stl_initeio(struct stlbrd *brdp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1844 | { |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 1845 | struct stlpanel *panelp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1846 | unsigned int status; |
| 1847 | char *name; |
Jiri Slaby | 3b85b34 | 2006-12-08 02:39:10 -0800 | [diff] [blame] | 1848 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1849 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 1850 | pr_debug("stl_initeio(brdp=%p)\n", brdp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1851 | |
| 1852 | brdp->ioctrl = brdp->ioaddr1 + 1; |
| 1853 | brdp->iostatus = brdp->ioaddr1 + 2; |
| 1854 | |
| 1855 | status = inb(brdp->iostatus); |
| 1856 | if ((status & EIO_IDBITMASK) == EIO_MK3) |
| 1857 | brdp->ioctrl++; |
| 1858 | |
| 1859 | /* |
| 1860 | * Handle board specific stuff now. The real difference is PCI |
| 1861 | * or not PCI. |
| 1862 | */ |
| 1863 | if (brdp->brdtype == BRD_EASYIOPCI) { |
| 1864 | brdp->iosize1 = 0x80; |
| 1865 | brdp->iosize2 = 0x80; |
| 1866 | name = "serial(EIO-PCI)"; |
| 1867 | outb(0x41, (brdp->ioaddr2 + 0x4c)); |
| 1868 | } else { |
| 1869 | brdp->iosize1 = 8; |
| 1870 | name = "serial(EIO)"; |
| 1871 | if ((brdp->irq < 0) || (brdp->irq > 15) || |
| 1872 | (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) { |
| 1873 | printk("STALLION: invalid irq=%d for brd=%d\n", |
| 1874 | brdp->irq, brdp->brdnr); |
Jiri Slaby | 3b85b34 | 2006-12-08 02:39:10 -0800 | [diff] [blame] | 1875 | retval = -EINVAL; |
| 1876 | goto err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1877 | } |
| 1878 | outb((stl_vecmap[brdp->irq] | EIO_0WS | |
| 1879 | ((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)), |
| 1880 | brdp->ioctrl); |
| 1881 | } |
| 1882 | |
Jiri Slaby | 3b85b34 | 2006-12-08 02:39:10 -0800 | [diff] [blame] | 1883 | retval = -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1884 | if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) { |
| 1885 | printk(KERN_WARNING "STALLION: Warning, board %d I/O address " |
| 1886 | "%x conflicts with another device\n", brdp->brdnr, |
| 1887 | brdp->ioaddr1); |
Jiri Slaby | 3b85b34 | 2006-12-08 02:39:10 -0800 | [diff] [blame] | 1888 | goto err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1889 | } |
| 1890 | |
| 1891 | if (brdp->iosize2 > 0) |
| 1892 | if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) { |
| 1893 | printk(KERN_WARNING "STALLION: Warning, board %d I/O " |
| 1894 | "address %x conflicts with another device\n", |
| 1895 | brdp->brdnr, brdp->ioaddr2); |
| 1896 | printk(KERN_WARNING "STALLION: Warning, also " |
| 1897 | "releasing board %d I/O address %x \n", |
| 1898 | brdp->brdnr, brdp->ioaddr1); |
Jiri Slaby | 3b85b34 | 2006-12-08 02:39:10 -0800 | [diff] [blame] | 1899 | goto err_rel1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1900 | } |
| 1901 | |
| 1902 | /* |
| 1903 | * Everything looks OK, so let's go ahead and probe for the hardware. |
| 1904 | */ |
| 1905 | brdp->clk = CD1400_CLK; |
| 1906 | brdp->isr = stl_eiointr; |
| 1907 | |
Jiri Slaby | 3b85b34 | 2006-12-08 02:39:10 -0800 | [diff] [blame] | 1908 | retval = -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1909 | switch (status & EIO_IDBITMASK) { |
| 1910 | case EIO_8PORTM: |
| 1911 | brdp->clk = CD1400_CLK8M; |
| 1912 | /* fall thru */ |
| 1913 | case EIO_8PORTRS: |
| 1914 | case EIO_8PORTDI: |
| 1915 | brdp->nrports = 8; |
| 1916 | break; |
| 1917 | case EIO_4PORTRS: |
| 1918 | brdp->nrports = 4; |
| 1919 | break; |
| 1920 | case EIO_MK3: |
| 1921 | switch (status & EIO_BRDMASK) { |
| 1922 | case ID_BRD4: |
| 1923 | brdp->nrports = 4; |
| 1924 | break; |
| 1925 | case ID_BRD8: |
| 1926 | brdp->nrports = 8; |
| 1927 | break; |
| 1928 | case ID_BRD16: |
| 1929 | brdp->nrports = 16; |
| 1930 | break; |
| 1931 | default: |
Jiri Slaby | 3b85b34 | 2006-12-08 02:39:10 -0800 | [diff] [blame] | 1932 | goto err_rel2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1933 | } |
| 1934 | break; |
| 1935 | default: |
Jiri Slaby | 3b85b34 | 2006-12-08 02:39:10 -0800 | [diff] [blame] | 1936 | goto err_rel2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1937 | } |
| 1938 | |
| 1939 | /* |
| 1940 | * We have verified that the board is actually present, so now we |
| 1941 | * can complete the setup. |
| 1942 | */ |
| 1943 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 1944 | panelp = kzalloc(sizeof(struct stlpanel), GFP_KERNEL); |
Tobias Klauser | b0b4ed7 | 2006-03-31 02:30:56 -0800 | [diff] [blame] | 1945 | if (!panelp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1946 | printk(KERN_WARNING "STALLION: failed to allocate memory " |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 1947 | "(size=%Zd)\n", sizeof(struct stlpanel)); |
Jiri Slaby | 3b85b34 | 2006-12-08 02:39:10 -0800 | [diff] [blame] | 1948 | retval = -ENOMEM; |
| 1949 | goto err_rel2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1950 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1951 | |
| 1952 | panelp->magic = STL_PANELMAGIC; |
| 1953 | panelp->brdnr = brdp->brdnr; |
| 1954 | panelp->panelnr = 0; |
| 1955 | panelp->nrports = brdp->nrports; |
| 1956 | panelp->iobase = brdp->ioaddr1; |
| 1957 | panelp->hwid = status; |
| 1958 | if ((status & EIO_IDBITMASK) == EIO_MK3) { |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 1959 | panelp->uartp = &stl_sc26198uart; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1960 | panelp->isr = stl_sc26198intr; |
| 1961 | } else { |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 1962 | panelp->uartp = &stl_cd1400uart; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1963 | panelp->isr = stl_cd1400eiointr; |
| 1964 | } |
| 1965 | |
| 1966 | brdp->panels[0] = panelp; |
| 1967 | brdp->nrpanels = 1; |
| 1968 | brdp->state |= BRD_FOUND; |
| 1969 | brdp->hwid = status; |
Thomas Gleixner | 0f2ed4c | 2006-07-01 19:29:33 -0700 | [diff] [blame] | 1970 | if (request_irq(brdp->irq, stl_intr, IRQF_SHARED, name, brdp) != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1971 | printk("STALLION: failed to register interrupt " |
| 1972 | "routine for %s irq=%d\n", name, brdp->irq); |
Jiri Slaby | 3b85b34 | 2006-12-08 02:39:10 -0800 | [diff] [blame] | 1973 | retval = -ENODEV; |
| 1974 | goto err_fr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1975 | } |
Jiri Slaby | 3b85b34 | 2006-12-08 02:39:10 -0800 | [diff] [blame] | 1976 | |
| 1977 | return 0; |
| 1978 | err_fr: |
| 1979 | stl_cleanup_panels(brdp); |
| 1980 | err_rel2: |
| 1981 | if (brdp->iosize2 > 0) |
| 1982 | release_region(brdp->ioaddr2, brdp->iosize2); |
| 1983 | err_rel1: |
| 1984 | release_region(brdp->ioaddr1, brdp->iosize1); |
| 1985 | err: |
| 1986 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1987 | } |
| 1988 | |
| 1989 | /*****************************************************************************/ |
| 1990 | |
| 1991 | /* |
| 1992 | * Try to find an ECH board and initialize it. This code is capable of |
| 1993 | * dealing with all types of ECH board. |
| 1994 | */ |
| 1995 | |
Jiri Slaby | 705c186 | 2006-12-08 02:39:11 -0800 | [diff] [blame] | 1996 | static int __devinit stl_initech(struct stlbrd *brdp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1997 | { |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 1998 | struct stlpanel *panelp; |
Jiri Slaby | 6b2c945 | 2006-12-08 02:39:15 -0800 | [diff] [blame] | 1999 | unsigned int status, nxtid, ioaddr, conflict, panelnr, banknr, i; |
| 2000 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2001 | char *name; |
| 2002 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 2003 | pr_debug("stl_initech(brdp=%p)\n", brdp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2004 | |
| 2005 | status = 0; |
| 2006 | conflict = 0; |
| 2007 | |
| 2008 | /* |
| 2009 | * Set up the initial board register contents for boards. This varies a |
| 2010 | * bit between the different board types. So we need to handle each |
| 2011 | * separately. Also do a check that the supplied IRQ is good. |
| 2012 | */ |
| 2013 | switch (brdp->brdtype) { |
| 2014 | |
| 2015 | case BRD_ECH: |
| 2016 | brdp->isr = stl_echatintr; |
| 2017 | brdp->ioctrl = brdp->ioaddr1 + 1; |
| 2018 | brdp->iostatus = brdp->ioaddr1 + 1; |
| 2019 | status = inb(brdp->iostatus); |
Jiri Slaby | 3b85b34 | 2006-12-08 02:39:10 -0800 | [diff] [blame] | 2020 | if ((status & ECH_IDBITMASK) != ECH_ID) { |
| 2021 | retval = -ENODEV; |
| 2022 | goto err; |
| 2023 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2024 | if ((brdp->irq < 0) || (brdp->irq > 15) || |
| 2025 | (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) { |
| 2026 | printk("STALLION: invalid irq=%d for brd=%d\n", |
| 2027 | brdp->irq, brdp->brdnr); |
Jiri Slaby | 3b85b34 | 2006-12-08 02:39:10 -0800 | [diff] [blame] | 2028 | retval = -EINVAL; |
| 2029 | goto err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2030 | } |
| 2031 | status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1); |
| 2032 | status |= (stl_vecmap[brdp->irq] << 1); |
| 2033 | outb((status | ECH_BRDRESET), brdp->ioaddr1); |
| 2034 | brdp->ioctrlval = ECH_INTENABLE | |
| 2035 | ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE); |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 2036 | for (i = 0; i < 10; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2037 | outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl); |
| 2038 | brdp->iosize1 = 2; |
| 2039 | brdp->iosize2 = 32; |
| 2040 | name = "serial(EC8/32)"; |
| 2041 | outb(status, brdp->ioaddr1); |
| 2042 | break; |
| 2043 | |
| 2044 | case BRD_ECHMC: |
| 2045 | brdp->isr = stl_echmcaintr; |
| 2046 | brdp->ioctrl = brdp->ioaddr1 + 0x20; |
| 2047 | brdp->iostatus = brdp->ioctrl; |
| 2048 | status = inb(brdp->iostatus); |
Jiri Slaby | 3b85b34 | 2006-12-08 02:39:10 -0800 | [diff] [blame] | 2049 | if ((status & ECH_IDBITMASK) != ECH_ID) { |
| 2050 | retval = -ENODEV; |
| 2051 | goto err; |
| 2052 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2053 | if ((brdp->irq < 0) || (brdp->irq > 15) || |
| 2054 | (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) { |
| 2055 | printk("STALLION: invalid irq=%d for brd=%d\n", |
| 2056 | brdp->irq, brdp->brdnr); |
Jiri Slaby | 3b85b34 | 2006-12-08 02:39:10 -0800 | [diff] [blame] | 2057 | retval = -EINVAL; |
| 2058 | goto err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2059 | } |
| 2060 | outb(ECHMC_BRDRESET, brdp->ioctrl); |
| 2061 | outb(ECHMC_INTENABLE, brdp->ioctrl); |
| 2062 | brdp->iosize1 = 64; |
| 2063 | name = "serial(EC8/32-MC)"; |
| 2064 | break; |
| 2065 | |
| 2066 | case BRD_ECHPCI: |
| 2067 | brdp->isr = stl_echpciintr; |
| 2068 | brdp->ioctrl = brdp->ioaddr1 + 2; |
| 2069 | brdp->iosize1 = 4; |
| 2070 | brdp->iosize2 = 8; |
| 2071 | name = "serial(EC8/32-PCI)"; |
| 2072 | break; |
| 2073 | |
| 2074 | case BRD_ECH64PCI: |
| 2075 | brdp->isr = stl_echpci64intr; |
| 2076 | brdp->ioctrl = brdp->ioaddr2 + 0x40; |
| 2077 | outb(0x43, (brdp->ioaddr1 + 0x4c)); |
| 2078 | brdp->iosize1 = 0x80; |
| 2079 | brdp->iosize2 = 0x80; |
| 2080 | name = "serial(EC8/64-PCI)"; |
| 2081 | break; |
| 2082 | |
| 2083 | default: |
| 2084 | printk("STALLION: unknown board type=%d\n", brdp->brdtype); |
Jiri Slaby | 3b85b34 | 2006-12-08 02:39:10 -0800 | [diff] [blame] | 2085 | retval = -EINVAL; |
| 2086 | goto err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2087 | } |
| 2088 | |
| 2089 | /* |
| 2090 | * Check boards for possible IO address conflicts and return fail status |
| 2091 | * if an IO conflict found. |
| 2092 | */ |
Jiri Slaby | 3b85b34 | 2006-12-08 02:39:10 -0800 | [diff] [blame] | 2093 | retval = -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2094 | if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) { |
| 2095 | printk(KERN_WARNING "STALLION: Warning, board %d I/O address " |
| 2096 | "%x conflicts with another device\n", brdp->brdnr, |
| 2097 | brdp->ioaddr1); |
Jiri Slaby | 3b85b34 | 2006-12-08 02:39:10 -0800 | [diff] [blame] | 2098 | goto err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2099 | } |
| 2100 | |
| 2101 | if (brdp->iosize2 > 0) |
| 2102 | if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) { |
| 2103 | printk(KERN_WARNING "STALLION: Warning, board %d I/O " |
| 2104 | "address %x conflicts with another device\n", |
| 2105 | brdp->brdnr, brdp->ioaddr2); |
| 2106 | printk(KERN_WARNING "STALLION: Warning, also " |
| 2107 | "releasing board %d I/O address %x \n", |
| 2108 | brdp->brdnr, brdp->ioaddr1); |
Jiri Slaby | 3b85b34 | 2006-12-08 02:39:10 -0800 | [diff] [blame] | 2109 | goto err_rel1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2110 | } |
| 2111 | |
| 2112 | /* |
| 2113 | * Scan through the secondary io address space looking for panels. |
| 2114 | * As we find'em allocate and initialize panel structures for each. |
| 2115 | */ |
| 2116 | brdp->clk = CD1400_CLK; |
| 2117 | brdp->hwid = status; |
| 2118 | |
| 2119 | ioaddr = brdp->ioaddr2; |
| 2120 | banknr = 0; |
| 2121 | panelnr = 0; |
| 2122 | nxtid = 0; |
| 2123 | |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 2124 | for (i = 0; i < STL_MAXPANELS; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2125 | if (brdp->brdtype == BRD_ECHPCI) { |
| 2126 | outb(nxtid, brdp->ioctrl); |
| 2127 | ioaddr = brdp->ioaddr2; |
| 2128 | } |
| 2129 | status = inb(ioaddr + ECH_PNLSTATUS); |
| 2130 | if ((status & ECH_PNLIDMASK) != nxtid) |
Jiri Slaby | 64834b2 | 2007-06-08 13:46:52 -0700 | [diff] [blame] | 2131 | break; |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 2132 | panelp = kzalloc(sizeof(struct stlpanel), GFP_KERNEL); |
Tobias Klauser | b0b4ed7 | 2006-03-31 02:30:56 -0800 | [diff] [blame] | 2133 | if (!panelp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2134 | printk("STALLION: failed to allocate memory " |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 2135 | "(size=%Zd)\n", sizeof(struct stlpanel)); |
Jiri Slaby | 49277b1 | 2007-06-08 13:46:53 -0700 | [diff] [blame] | 2136 | retval = -ENOMEM; |
Jiri Slaby | 3b85b34 | 2006-12-08 02:39:10 -0800 | [diff] [blame] | 2137 | goto err_fr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2138 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2139 | panelp->magic = STL_PANELMAGIC; |
| 2140 | panelp->brdnr = brdp->brdnr; |
| 2141 | panelp->panelnr = panelnr; |
| 2142 | panelp->iobase = ioaddr; |
| 2143 | panelp->pagenr = nxtid; |
| 2144 | panelp->hwid = status; |
| 2145 | brdp->bnk2panel[banknr] = panelp; |
| 2146 | brdp->bnkpageaddr[banknr] = nxtid; |
| 2147 | brdp->bnkstataddr[banknr++] = ioaddr + ECH_PNLSTATUS; |
| 2148 | |
| 2149 | if (status & ECH_PNLXPID) { |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 2150 | panelp->uartp = &stl_sc26198uart; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2151 | panelp->isr = stl_sc26198intr; |
| 2152 | if (status & ECH_PNL16PORT) { |
| 2153 | panelp->nrports = 16; |
| 2154 | brdp->bnk2panel[banknr] = panelp; |
| 2155 | brdp->bnkpageaddr[banknr] = nxtid; |
| 2156 | brdp->bnkstataddr[banknr++] = ioaddr + 4 + |
| 2157 | ECH_PNLSTATUS; |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 2158 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2159 | panelp->nrports = 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2160 | } else { |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 2161 | panelp->uartp = &stl_cd1400uart; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2162 | panelp->isr = stl_cd1400echintr; |
| 2163 | if (status & ECH_PNL16PORT) { |
| 2164 | panelp->nrports = 16; |
| 2165 | panelp->ackmask = 0x80; |
| 2166 | if (brdp->brdtype != BRD_ECHPCI) |
| 2167 | ioaddr += EREG_BANKSIZE; |
| 2168 | brdp->bnk2panel[banknr] = panelp; |
| 2169 | brdp->bnkpageaddr[banknr] = ++nxtid; |
| 2170 | brdp->bnkstataddr[banknr++] = ioaddr + |
| 2171 | ECH_PNLSTATUS; |
| 2172 | } else { |
| 2173 | panelp->nrports = 8; |
| 2174 | panelp->ackmask = 0xc0; |
| 2175 | } |
| 2176 | } |
| 2177 | |
| 2178 | nxtid++; |
| 2179 | ioaddr += EREG_BANKSIZE; |
| 2180 | brdp->nrports += panelp->nrports; |
| 2181 | brdp->panels[panelnr++] = panelp; |
| 2182 | if ((brdp->brdtype != BRD_ECHPCI) && |
Jiri Slaby | 49277b1 | 2007-06-08 13:46:53 -0700 | [diff] [blame] | 2183 | (ioaddr >= (brdp->ioaddr2 + brdp->iosize2))) { |
| 2184 | retval = -EINVAL; |
Jiri Slaby | 3b85b34 | 2006-12-08 02:39:10 -0800 | [diff] [blame] | 2185 | goto err_fr; |
Jiri Slaby | 49277b1 | 2007-06-08 13:46:53 -0700 | [diff] [blame] | 2186 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2187 | } |
| 2188 | |
| 2189 | brdp->nrpanels = panelnr; |
| 2190 | brdp->nrbnks = banknr; |
| 2191 | if (brdp->brdtype == BRD_ECH) |
| 2192 | outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl); |
| 2193 | |
| 2194 | brdp->state |= BRD_FOUND; |
Thomas Gleixner | 0f2ed4c | 2006-07-01 19:29:33 -0700 | [diff] [blame] | 2195 | if (request_irq(brdp->irq, stl_intr, IRQF_SHARED, name, brdp) != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2196 | printk("STALLION: failed to register interrupt " |
| 2197 | "routine for %s irq=%d\n", name, brdp->irq); |
Jiri Slaby | 3b85b34 | 2006-12-08 02:39:10 -0800 | [diff] [blame] | 2198 | retval = -ENODEV; |
| 2199 | goto err_fr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2200 | } |
| 2201 | |
Jiri Slaby | 3b85b34 | 2006-12-08 02:39:10 -0800 | [diff] [blame] | 2202 | return 0; |
| 2203 | err_fr: |
| 2204 | stl_cleanup_panels(brdp); |
| 2205 | if (brdp->iosize2 > 0) |
| 2206 | release_region(brdp->ioaddr2, brdp->iosize2); |
| 2207 | err_rel1: |
| 2208 | release_region(brdp->ioaddr1, brdp->iosize1); |
| 2209 | err: |
| 2210 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2211 | } |
| 2212 | |
| 2213 | /*****************************************************************************/ |
| 2214 | |
| 2215 | /* |
| 2216 | * Initialize and configure the specified board. |
| 2217 | * Scan through all the boards in the configuration and see what we |
| 2218 | * can find. Handle EIO and the ECH boards a little differently here |
| 2219 | * since the initial search and setup is very different. |
| 2220 | */ |
| 2221 | |
Jiri Slaby | 705c186 | 2006-12-08 02:39:11 -0800 | [diff] [blame] | 2222 | static int __devinit stl_brdinit(struct stlbrd *brdp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2223 | { |
Jiri Slaby | 3b85b34 | 2006-12-08 02:39:10 -0800 | [diff] [blame] | 2224 | int i, retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2225 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 2226 | pr_debug("stl_brdinit(brdp=%p)\n", brdp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2227 | |
| 2228 | switch (brdp->brdtype) { |
| 2229 | case BRD_EASYIO: |
| 2230 | case BRD_EASYIOPCI: |
Jiri Slaby | 3b85b34 | 2006-12-08 02:39:10 -0800 | [diff] [blame] | 2231 | retval = stl_initeio(brdp); |
| 2232 | if (retval) |
| 2233 | goto err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2234 | break; |
| 2235 | case BRD_ECH: |
| 2236 | case BRD_ECHMC: |
| 2237 | case BRD_ECHPCI: |
| 2238 | case BRD_ECH64PCI: |
Jiri Slaby | 3b85b34 | 2006-12-08 02:39:10 -0800 | [diff] [blame] | 2239 | retval = stl_initech(brdp); |
| 2240 | if (retval) |
| 2241 | goto err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2242 | break; |
| 2243 | default: |
| 2244 | printk("STALLION: board=%d is unknown board type=%d\n", |
| 2245 | brdp->brdnr, brdp->brdtype); |
Jiri Slaby | 3b85b34 | 2006-12-08 02:39:10 -0800 | [diff] [blame] | 2246 | retval = -ENODEV; |
| 2247 | goto err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2248 | } |
| 2249 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2250 | if ((brdp->state & BRD_FOUND) == 0) { |
| 2251 | printk("STALLION: %s board not found, board=%d io=%x irq=%d\n", |
| 2252 | stl_brdnames[brdp->brdtype], brdp->brdnr, |
| 2253 | brdp->ioaddr1, brdp->irq); |
Jiri Slaby | 3b85b34 | 2006-12-08 02:39:10 -0800 | [diff] [blame] | 2254 | goto err_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2255 | } |
| 2256 | |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 2257 | for (i = 0; i < STL_MAXPANELS; i++) |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 2258 | if (brdp->panels[i] != NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2259 | stl_initports(brdp, brdp->panels[i]); |
| 2260 | |
| 2261 | printk("STALLION: %s found, board=%d io=%x irq=%d " |
| 2262 | "nrpanels=%d nrports=%d\n", stl_brdnames[brdp->brdtype], |
| 2263 | brdp->brdnr, brdp->ioaddr1, brdp->irq, brdp->nrpanels, |
| 2264 | brdp->nrports); |
Jiri Slaby | 3b85b34 | 2006-12-08 02:39:10 -0800 | [diff] [blame] | 2265 | |
| 2266 | return 0; |
| 2267 | err_free: |
| 2268 | free_irq(brdp->irq, brdp); |
| 2269 | |
| 2270 | stl_cleanup_panels(brdp); |
| 2271 | |
| 2272 | release_region(brdp->ioaddr1, brdp->iosize1); |
| 2273 | if (brdp->iosize2 > 0) |
| 2274 | release_region(brdp->ioaddr2, brdp->iosize2); |
Jiri Slaby | 3b85b34 | 2006-12-08 02:39:10 -0800 | [diff] [blame] | 2275 | err: |
| 2276 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2277 | } |
| 2278 | |
| 2279 | /*****************************************************************************/ |
| 2280 | |
| 2281 | /* |
| 2282 | * Find the next available board number that is free. |
| 2283 | */ |
| 2284 | |
Jiri Slaby | 705c186 | 2006-12-08 02:39:11 -0800 | [diff] [blame] | 2285 | static int __devinit stl_getbrdnr(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2286 | { |
Jiri Slaby | 6b2c945 | 2006-12-08 02:39:15 -0800 | [diff] [blame] | 2287 | unsigned int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2288 | |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 2289 | for (i = 0; i < STL_MAXBRDS; i++) |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 2290 | if (stl_brds[i] == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2291 | if (i >= stl_nrbrds) |
| 2292 | stl_nrbrds = i + 1; |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 2293 | return i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2294 | } |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 2295 | |
| 2296 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2297 | } |
| 2298 | |
| 2299 | /*****************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2300 | /* |
| 2301 | * We have a Stallion board. Allocate a board structure and |
| 2302 | * initialize it. Read its IO and IRQ resources from PCI |
| 2303 | * configuration space. |
| 2304 | */ |
| 2305 | |
Jiri Slaby | b1b84fe | 2006-12-08 02:39:09 -0800 | [diff] [blame] | 2306 | static int __devinit stl_pciprobe(struct pci_dev *pdev, |
| 2307 | const struct pci_device_id *ent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2308 | { |
Jiri Slaby | b1b84fe | 2006-12-08 02:39:09 -0800 | [diff] [blame] | 2309 | struct stlbrd *brdp; |
Jiri Slaby | aeaccfe | 2006-12-08 02:39:16 -0800 | [diff] [blame] | 2310 | unsigned int i, brdtype = ent->driver_data; |
Jiri Slaby | 6b2c945 | 2006-12-08 02:39:15 -0800 | [diff] [blame] | 2311 | int brdnr, retval = -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2312 | |
Jiri Slaby | b1b84fe | 2006-12-08 02:39:09 -0800 | [diff] [blame] | 2313 | if ((pdev->class >> 8) == PCI_CLASS_STORAGE_IDE) |
Jiri Slaby | 3b85b34 | 2006-12-08 02:39:10 -0800 | [diff] [blame] | 2314 | goto err; |
Jiri Slaby | b1b84fe | 2006-12-08 02:39:09 -0800 | [diff] [blame] | 2315 | |
Jiri Slaby | 3b85b34 | 2006-12-08 02:39:10 -0800 | [diff] [blame] | 2316 | retval = pci_enable_device(pdev); |
| 2317 | if (retval) |
| 2318 | goto err; |
| 2319 | brdp = stl_allocbrd(); |
| 2320 | if (brdp == NULL) { |
| 2321 | retval = -ENOMEM; |
| 2322 | goto err; |
| 2323 | } |
Jiri Slaby | 79cfe7a | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 2324 | mutex_lock(&stl_brdslock); |
Jiri Slaby | 6b2c945 | 2006-12-08 02:39:15 -0800 | [diff] [blame] | 2325 | brdnr = stl_getbrdnr(); |
| 2326 | if (brdnr < 0) { |
Jiri Slaby | fefaf9a | 2006-12-08 02:39:09 -0800 | [diff] [blame] | 2327 | dev_err(&pdev->dev, "too many boards found, " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2328 | "maximum supported %d\n", STL_MAXBRDS); |
Jiri Slaby | 79cfe7a | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 2329 | mutex_unlock(&stl_brdslock); |
Jiri Slaby | 49277b1 | 2007-06-08 13:46:53 -0700 | [diff] [blame] | 2330 | retval = -ENODEV; |
Jiri Slaby | 3b85b34 | 2006-12-08 02:39:10 -0800 | [diff] [blame] | 2331 | goto err_fr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2332 | } |
Jiri Slaby | 6b2c945 | 2006-12-08 02:39:15 -0800 | [diff] [blame] | 2333 | brdp->brdnr = (unsigned int)brdnr; |
Jiri Slaby | 79cfe7a | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 2334 | stl_brds[brdp->brdnr] = brdp; |
| 2335 | mutex_unlock(&stl_brdslock); |
| 2336 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2337 | brdp->brdtype = brdtype; |
Jiri Slaby | fc06b5c | 2006-12-08 02:39:13 -0800 | [diff] [blame] | 2338 | brdp->state |= STL_PROBED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2339 | |
| 2340 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2341 | * We have all resources from the board, so let's setup the actual |
| 2342 | * board structure now. |
| 2343 | */ |
| 2344 | switch (brdtype) { |
| 2345 | case BRD_ECHPCI: |
Jiri Slaby | b1b84fe | 2006-12-08 02:39:09 -0800 | [diff] [blame] | 2346 | brdp->ioaddr2 = pci_resource_start(pdev, 0); |
| 2347 | brdp->ioaddr1 = pci_resource_start(pdev, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2348 | break; |
| 2349 | case BRD_ECH64PCI: |
Jiri Slaby | b1b84fe | 2006-12-08 02:39:09 -0800 | [diff] [blame] | 2350 | brdp->ioaddr2 = pci_resource_start(pdev, 2); |
| 2351 | brdp->ioaddr1 = pci_resource_start(pdev, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2352 | break; |
| 2353 | case BRD_EASYIOPCI: |
Jiri Slaby | b1b84fe | 2006-12-08 02:39:09 -0800 | [diff] [blame] | 2354 | brdp->ioaddr1 = pci_resource_start(pdev, 2); |
| 2355 | brdp->ioaddr2 = pci_resource_start(pdev, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2356 | break; |
| 2357 | default: |
Jiri Slaby | fefaf9a | 2006-12-08 02:39:09 -0800 | [diff] [blame] | 2358 | dev_err(&pdev->dev, "unknown PCI board type=%u\n", brdtype); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2359 | break; |
| 2360 | } |
| 2361 | |
Jiri Slaby | b1b84fe | 2006-12-08 02:39:09 -0800 | [diff] [blame] | 2362 | brdp->irq = pdev->irq; |
Jiri Slaby | 3b85b34 | 2006-12-08 02:39:10 -0800 | [diff] [blame] | 2363 | retval = stl_brdinit(brdp); |
| 2364 | if (retval) |
Jiri Slaby | 79cfe7a | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 2365 | goto err_null; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2366 | |
Jiri Slaby | b1b84fe | 2006-12-08 02:39:09 -0800 | [diff] [blame] | 2367 | pci_set_drvdata(pdev, brdp); |
| 2368 | |
Jiri Slaby | aeaccfe | 2006-12-08 02:39:16 -0800 | [diff] [blame] | 2369 | for (i = 0; i < brdp->nrports; i++) |
| 2370 | tty_register_device(stl_serial, |
| 2371 | brdp->brdnr * STL_MAXPORTS + i, &pdev->dev); |
| 2372 | |
Jiri Slaby | 3b85b34 | 2006-12-08 02:39:10 -0800 | [diff] [blame] | 2373 | return 0; |
Jiri Slaby | 79cfe7a | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 2374 | err_null: |
| 2375 | stl_brds[brdp->brdnr] = NULL; |
Jiri Slaby | 3b85b34 | 2006-12-08 02:39:10 -0800 | [diff] [blame] | 2376 | err_fr: |
| 2377 | kfree(brdp); |
| 2378 | err: |
| 2379 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2380 | } |
| 2381 | |
Jiri Slaby | b1b84fe | 2006-12-08 02:39:09 -0800 | [diff] [blame] | 2382 | static void __devexit stl_pciremove(struct pci_dev *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2383 | { |
Jiri Slaby | b1b84fe | 2006-12-08 02:39:09 -0800 | [diff] [blame] | 2384 | struct stlbrd *brdp = pci_get_drvdata(pdev); |
Jiri Slaby | aeaccfe | 2006-12-08 02:39:16 -0800 | [diff] [blame] | 2385 | unsigned int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2386 | |
Jiri Slaby | b1b84fe | 2006-12-08 02:39:09 -0800 | [diff] [blame] | 2387 | free_irq(brdp->irq, brdp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2388 | |
Jiri Slaby | b1b84fe | 2006-12-08 02:39:09 -0800 | [diff] [blame] | 2389 | stl_cleanup_panels(brdp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2390 | |
Jiri Slaby | b1b84fe | 2006-12-08 02:39:09 -0800 | [diff] [blame] | 2391 | release_region(brdp->ioaddr1, brdp->iosize1); |
| 2392 | if (brdp->iosize2 > 0) |
| 2393 | release_region(brdp->ioaddr2, brdp->iosize2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2394 | |
Jiri Slaby | aeaccfe | 2006-12-08 02:39:16 -0800 | [diff] [blame] | 2395 | for (i = 0; i < brdp->nrports; i++) |
| 2396 | tty_unregister_device(stl_serial, |
| 2397 | brdp->brdnr * STL_MAXPORTS + i); |
| 2398 | |
Jiri Slaby | b1b84fe | 2006-12-08 02:39:09 -0800 | [diff] [blame] | 2399 | stl_brds[brdp->brdnr] = NULL; |
| 2400 | kfree(brdp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2401 | } |
| 2402 | |
Jiri Slaby | b1b84fe | 2006-12-08 02:39:09 -0800 | [diff] [blame] | 2403 | static struct pci_driver stl_pcidriver = { |
| 2404 | .name = "stallion", |
| 2405 | .id_table = stl_pcibrds, |
| 2406 | .probe = stl_pciprobe, |
| 2407 | .remove = __devexit_p(stl_pciremove) |
| 2408 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2409 | |
| 2410 | /*****************************************************************************/ |
| 2411 | |
| 2412 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2413 | * Return the board stats structure to user app. |
| 2414 | */ |
| 2415 | |
| 2416 | static int stl_getbrdstats(combrd_t __user *bp) |
| 2417 | { |
Jiri Slaby | 6b2c945 | 2006-12-08 02:39:15 -0800 | [diff] [blame] | 2418 | combrd_t stl_brdstats; |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 2419 | struct stlbrd *brdp; |
| 2420 | struct stlpanel *panelp; |
Jiri Slaby | 6b2c945 | 2006-12-08 02:39:15 -0800 | [diff] [blame] | 2421 | unsigned int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2422 | |
| 2423 | if (copy_from_user(&stl_brdstats, bp, sizeof(combrd_t))) |
| 2424 | return -EFAULT; |
| 2425 | if (stl_brdstats.brd >= STL_MAXBRDS) |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 2426 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2427 | brdp = stl_brds[stl_brdstats.brd]; |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 2428 | if (brdp == NULL) |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 2429 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2430 | |
| 2431 | memset(&stl_brdstats, 0, sizeof(combrd_t)); |
| 2432 | stl_brdstats.brd = brdp->brdnr; |
| 2433 | stl_brdstats.type = brdp->brdtype; |
| 2434 | stl_brdstats.hwid = brdp->hwid; |
| 2435 | stl_brdstats.state = brdp->state; |
| 2436 | stl_brdstats.ioaddr = brdp->ioaddr1; |
| 2437 | stl_brdstats.ioaddr2 = brdp->ioaddr2; |
| 2438 | stl_brdstats.irq = brdp->irq; |
| 2439 | stl_brdstats.nrpanels = brdp->nrpanels; |
| 2440 | stl_brdstats.nrports = brdp->nrports; |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 2441 | for (i = 0; i < brdp->nrpanels; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2442 | panelp = brdp->panels[i]; |
| 2443 | stl_brdstats.panels[i].panel = i; |
| 2444 | stl_brdstats.panels[i].hwid = panelp->hwid; |
| 2445 | stl_brdstats.panels[i].nrports = panelp->nrports; |
| 2446 | } |
| 2447 | |
| 2448 | return copy_to_user(bp, &stl_brdstats, sizeof(combrd_t)) ? -EFAULT : 0; |
| 2449 | } |
| 2450 | |
| 2451 | /*****************************************************************************/ |
| 2452 | |
| 2453 | /* |
| 2454 | * Resolve the referenced port number into a port struct pointer. |
| 2455 | */ |
| 2456 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 2457 | static struct stlport *stl_getport(int brdnr, int panelnr, int portnr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2458 | { |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 2459 | struct stlbrd *brdp; |
| 2460 | struct stlpanel *panelp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2461 | |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 2462 | if (brdnr < 0 || brdnr >= STL_MAXBRDS) |
| 2463 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2464 | brdp = stl_brds[brdnr]; |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 2465 | if (brdp == NULL) |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 2466 | return NULL; |
Jiri Slaby | 6b2c945 | 2006-12-08 02:39:15 -0800 | [diff] [blame] | 2467 | if (panelnr < 0 || (unsigned int)panelnr >= brdp->nrpanels) |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 2468 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2469 | panelp = brdp->panels[panelnr]; |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 2470 | if (panelp == NULL) |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 2471 | return NULL; |
Jiri Slaby | 6b2c945 | 2006-12-08 02:39:15 -0800 | [diff] [blame] | 2472 | if (portnr < 0 || (unsigned int)portnr >= panelp->nrports) |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 2473 | return NULL; |
| 2474 | return panelp->ports[portnr]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2475 | } |
| 2476 | |
| 2477 | /*****************************************************************************/ |
| 2478 | |
| 2479 | /* |
| 2480 | * Return the port stats structure to user app. A NULL port struct |
| 2481 | * pointer passed in means that we need to find out from the app |
| 2482 | * what port to get stats for (used through board control device). |
| 2483 | */ |
| 2484 | |
Alan Cox | d18a750 | 2008-10-13 10:40:07 +0100 | [diff] [blame] | 2485 | static int stl_getportstats(struct tty_struct *tty, struct stlport *portp, comstats_t __user *cp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2486 | { |
Jiri Slaby | 6b2c945 | 2006-12-08 02:39:15 -0800 | [diff] [blame] | 2487 | comstats_t stl_comstats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2488 | unsigned char *head, *tail; |
| 2489 | unsigned long flags; |
| 2490 | |
| 2491 | if (!portp) { |
| 2492 | if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t))) |
| 2493 | return -EFAULT; |
| 2494 | portp = stl_getport(stl_comstats.brd, stl_comstats.panel, |
| 2495 | stl_comstats.port); |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 2496 | if (portp == NULL) |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 2497 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2498 | } |
| 2499 | |
| 2500 | portp->stats.state = portp->istate; |
Alan Cox | f8ae476 | 2008-07-16 21:56:37 +0100 | [diff] [blame] | 2501 | portp->stats.flags = portp->port.flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2502 | portp->stats.hwid = portp->hwid; |
| 2503 | |
| 2504 | portp->stats.ttystate = 0; |
| 2505 | portp->stats.cflags = 0; |
| 2506 | portp->stats.iflags = 0; |
| 2507 | portp->stats.oflags = 0; |
| 2508 | portp->stats.lflags = 0; |
| 2509 | portp->stats.rxbuffered = 0; |
| 2510 | |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 2511 | spin_lock_irqsave(&stallion_lock, flags); |
Alan Cox | d18a750 | 2008-10-13 10:40:07 +0100 | [diff] [blame] | 2512 | if (tty != NULL && portp->port.tty == tty) { |
| 2513 | portp->stats.ttystate = tty->flags; |
| 2514 | /* No longer available as a statistic */ |
| 2515 | portp->stats.rxbuffered = 1; /*tty->flip.count; */ |
| 2516 | if (tty->termios != NULL) { |
| 2517 | portp->stats.cflags = tty->termios->c_cflag; |
| 2518 | portp->stats.iflags = tty->termios->c_iflag; |
| 2519 | portp->stats.oflags = tty->termios->c_oflag; |
| 2520 | portp->stats.lflags = tty->termios->c_lflag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2521 | } |
Alan Cox | d18a750 | 2008-10-13 10:40:07 +0100 | [diff] [blame] | 2522 | } |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 2523 | spin_unlock_irqrestore(&stallion_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2524 | |
| 2525 | head = portp->tx.head; |
| 2526 | tail = portp->tx.tail; |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 2527 | portp->stats.txbuffered = (head >= tail) ? (head - tail) : |
| 2528 | (STL_TXBUFSIZE - (tail - head)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2529 | |
| 2530 | portp->stats.signals = (unsigned long) stl_getsignals(portp); |
| 2531 | |
| 2532 | return copy_to_user(cp, &portp->stats, |
| 2533 | sizeof(comstats_t)) ? -EFAULT : 0; |
| 2534 | } |
| 2535 | |
| 2536 | /*****************************************************************************/ |
| 2537 | |
| 2538 | /* |
| 2539 | * Clear the port stats structure. We also return it zeroed out... |
| 2540 | */ |
| 2541 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 2542 | static int stl_clrportstats(struct stlport *portp, comstats_t __user *cp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2543 | { |
Jiri Slaby | 6b2c945 | 2006-12-08 02:39:15 -0800 | [diff] [blame] | 2544 | comstats_t stl_comstats; |
| 2545 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2546 | if (!portp) { |
| 2547 | if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t))) |
| 2548 | return -EFAULT; |
| 2549 | portp = stl_getport(stl_comstats.brd, stl_comstats.panel, |
| 2550 | stl_comstats.port); |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 2551 | if (portp == NULL) |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 2552 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2553 | } |
| 2554 | |
| 2555 | memset(&portp->stats, 0, sizeof(comstats_t)); |
| 2556 | portp->stats.brd = portp->brdnr; |
| 2557 | portp->stats.panel = portp->panelnr; |
| 2558 | portp->stats.port = portp->portnr; |
| 2559 | return copy_to_user(cp, &portp->stats, |
| 2560 | sizeof(comstats_t)) ? -EFAULT : 0; |
| 2561 | } |
| 2562 | |
| 2563 | /*****************************************************************************/ |
| 2564 | |
| 2565 | /* |
| 2566 | * Return the entire driver ports structure to a user app. |
| 2567 | */ |
| 2568 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 2569 | static int stl_getportstruct(struct stlport __user *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2570 | { |
Jiri Slaby | 6b2c945 | 2006-12-08 02:39:15 -0800 | [diff] [blame] | 2571 | struct stlport stl_dummyport; |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 2572 | struct stlport *portp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2573 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 2574 | if (copy_from_user(&stl_dummyport, arg, sizeof(struct stlport))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2575 | return -EFAULT; |
| 2576 | portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr, |
| 2577 | stl_dummyport.portnr); |
| 2578 | if (!portp) |
| 2579 | return -ENODEV; |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 2580 | return copy_to_user(arg, portp, sizeof(struct stlport)) ? -EFAULT : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2581 | } |
| 2582 | |
| 2583 | /*****************************************************************************/ |
| 2584 | |
| 2585 | /* |
| 2586 | * Return the entire driver board structure to a user app. |
| 2587 | */ |
| 2588 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 2589 | static int stl_getbrdstruct(struct stlbrd __user *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2590 | { |
Jiri Slaby | 6b2c945 | 2006-12-08 02:39:15 -0800 | [diff] [blame] | 2591 | struct stlbrd stl_dummybrd; |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 2592 | struct stlbrd *brdp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2593 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 2594 | if (copy_from_user(&stl_dummybrd, arg, sizeof(struct stlbrd))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2595 | return -EFAULT; |
Jiri Slaby | 6b2c945 | 2006-12-08 02:39:15 -0800 | [diff] [blame] | 2596 | if (stl_dummybrd.brdnr >= STL_MAXBRDS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2597 | return -ENODEV; |
| 2598 | brdp = stl_brds[stl_dummybrd.brdnr]; |
| 2599 | if (!brdp) |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 2600 | return -ENODEV; |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 2601 | return copy_to_user(arg, brdp, sizeof(struct stlbrd)) ? -EFAULT : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2602 | } |
| 2603 | |
| 2604 | /*****************************************************************************/ |
| 2605 | |
| 2606 | /* |
| 2607 | * The "staliomem" device is also required to do some special operations |
| 2608 | * on the board and/or ports. In this driver it is mostly used for stats |
| 2609 | * collection. |
| 2610 | */ |
| 2611 | |
| 2612 | static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg) |
| 2613 | { |
| 2614 | int brdnr, rc; |
| 2615 | void __user *argp = (void __user *)arg; |
| 2616 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 2617 | pr_debug("stl_memioctl(ip=%p,fp=%p,cmd=%x,arg=%lx)\n", ip, fp, cmd,arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2618 | |
| 2619 | brdnr = iminor(ip); |
| 2620 | if (brdnr >= STL_MAXBRDS) |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 2621 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2622 | rc = 0; |
| 2623 | |
| 2624 | switch (cmd) { |
| 2625 | case COM_GETPORTSTATS: |
Alan Cox | d18a750 | 2008-10-13 10:40:07 +0100 | [diff] [blame] | 2626 | rc = stl_getportstats(NULL, NULL, argp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2627 | break; |
| 2628 | case COM_CLRPORTSTATS: |
| 2629 | rc = stl_clrportstats(NULL, argp); |
| 2630 | break; |
| 2631 | case COM_GETBRDSTATS: |
| 2632 | rc = stl_getbrdstats(argp); |
| 2633 | break; |
| 2634 | case COM_READPORT: |
| 2635 | rc = stl_getportstruct(argp); |
| 2636 | break; |
| 2637 | case COM_READBOARD: |
| 2638 | rc = stl_getbrdstruct(argp); |
| 2639 | break; |
| 2640 | default: |
| 2641 | rc = -ENOIOCTLCMD; |
| 2642 | break; |
| 2643 | } |
| 2644 | |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 2645 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2646 | } |
| 2647 | |
Jeff Dike | b68e31d | 2006-10-02 02:17:18 -0700 | [diff] [blame] | 2648 | static const struct tty_operations stl_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2649 | .open = stl_open, |
| 2650 | .close = stl_close, |
| 2651 | .write = stl_write, |
| 2652 | .put_char = stl_putchar, |
| 2653 | .flush_chars = stl_flushchars, |
| 2654 | .write_room = stl_writeroom, |
| 2655 | .chars_in_buffer = stl_charsinbuffer, |
| 2656 | .ioctl = stl_ioctl, |
| 2657 | .set_termios = stl_settermios, |
| 2658 | .throttle = stl_throttle, |
| 2659 | .unthrottle = stl_unthrottle, |
| 2660 | .stop = stl_stop, |
| 2661 | .start = stl_start, |
| 2662 | .hangup = stl_hangup, |
| 2663 | .flush_buffer = stl_flushbuffer, |
| 2664 | .break_ctl = stl_breakctl, |
| 2665 | .wait_until_sent = stl_waituntilsent, |
| 2666 | .send_xchar = stl_sendxchar, |
| 2667 | .read_proc = stl_readproc, |
| 2668 | .tiocmget = stl_tiocmget, |
| 2669 | .tiocmset = stl_tiocmset, |
| 2670 | }; |
| 2671 | |
Alan Cox | 31f3593 | 2009-01-02 13:45:05 +0000 | [diff] [blame^] | 2672 | static const struct tty_port_operations stl_port_ops = { |
| 2673 | .carrier_raised = stl_carrier_raised, |
| 2674 | }; |
| 2675 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2676 | /*****************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2677 | /* CD1400 HARDWARE FUNCTIONS */ |
| 2678 | /*****************************************************************************/ |
| 2679 | |
| 2680 | /* |
| 2681 | * These functions get/set/update the registers of the cd1400 UARTs. |
| 2682 | * Access to the cd1400 registers is via an address/data io port pair. |
| 2683 | * (Maybe should make this inline...) |
| 2684 | */ |
| 2685 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 2686 | static int stl_cd1400getreg(struct stlport *portp, int regnr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2687 | { |
| 2688 | outb((regnr + portp->uartaddr), portp->ioaddr); |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 2689 | return inb(portp->ioaddr + EREG_DATA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2690 | } |
| 2691 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 2692 | static void stl_cd1400setreg(struct stlport *portp, int regnr, int value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2693 | { |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 2694 | outb(regnr + portp->uartaddr, portp->ioaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2695 | outb(value, portp->ioaddr + EREG_DATA); |
| 2696 | } |
| 2697 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 2698 | static int stl_cd1400updatereg(struct stlport *portp, int regnr, int value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2699 | { |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 2700 | outb(regnr + portp->uartaddr, portp->ioaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2701 | if (inb(portp->ioaddr + EREG_DATA) != value) { |
| 2702 | outb(value, portp->ioaddr + EREG_DATA); |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 2703 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2704 | } |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 2705 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2706 | } |
| 2707 | |
| 2708 | /*****************************************************************************/ |
| 2709 | |
| 2710 | /* |
| 2711 | * Inbitialize the UARTs in a panel. We don't care what sort of board |
| 2712 | * these ports are on - since the port io registers are almost |
| 2713 | * identical when dealing with ports. |
| 2714 | */ |
| 2715 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 2716 | static int stl_cd1400panelinit(struct stlbrd *brdp, struct stlpanel *panelp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2717 | { |
| 2718 | unsigned int gfrcr; |
| 2719 | int chipmask, i, j; |
| 2720 | int nrchips, uartaddr, ioaddr; |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 2721 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2722 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 2723 | pr_debug("stl_panelinit(brdp=%p,panelp=%p)\n", brdp, panelp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2724 | |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 2725 | spin_lock_irqsave(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2726 | BRDENABLE(panelp->brdnr, panelp->pagenr); |
| 2727 | |
| 2728 | /* |
| 2729 | * Check that each chip is present and started up OK. |
| 2730 | */ |
| 2731 | chipmask = 0; |
| 2732 | nrchips = panelp->nrports / CD1400_PORTS; |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 2733 | for (i = 0; i < nrchips; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2734 | if (brdp->brdtype == BRD_ECHPCI) { |
| 2735 | outb((panelp->pagenr + (i >> 1)), brdp->ioctrl); |
| 2736 | ioaddr = panelp->iobase; |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 2737 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2738 | ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2739 | uartaddr = (i & 0x01) ? 0x080 : 0; |
| 2740 | outb((GFRCR + uartaddr), ioaddr); |
| 2741 | outb(0, (ioaddr + EREG_DATA)); |
| 2742 | outb((CCR + uartaddr), ioaddr); |
| 2743 | outb(CCR_RESETFULL, (ioaddr + EREG_DATA)); |
| 2744 | outb(CCR_RESETFULL, (ioaddr + EREG_DATA)); |
| 2745 | outb((GFRCR + uartaddr), ioaddr); |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 2746 | for (j = 0; j < CCR_MAXWAIT; j++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2747 | if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0) |
| 2748 | break; |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 2749 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2750 | if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) { |
| 2751 | printk("STALLION: cd1400 not responding, " |
| 2752 | "brd=%d panel=%d chip=%d\n", |
| 2753 | panelp->brdnr, panelp->panelnr, i); |
| 2754 | continue; |
| 2755 | } |
| 2756 | chipmask |= (0x1 << i); |
| 2757 | outb((PPR + uartaddr), ioaddr); |
| 2758 | outb(PPR_SCALAR, (ioaddr + EREG_DATA)); |
| 2759 | } |
| 2760 | |
| 2761 | BRDDISABLE(panelp->brdnr); |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 2762 | spin_unlock_irqrestore(&brd_lock, flags); |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 2763 | return chipmask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2764 | } |
| 2765 | |
| 2766 | /*****************************************************************************/ |
| 2767 | |
| 2768 | /* |
| 2769 | * Initialize hardware specific port registers. |
| 2770 | */ |
| 2771 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 2772 | static void stl_cd1400portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2773 | { |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 2774 | unsigned long flags; |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 2775 | pr_debug("stl_cd1400portinit(brdp=%p,panelp=%p,portp=%p)\n", brdp, |
| 2776 | panelp, portp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2777 | |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 2778 | if ((brdp == NULL) || (panelp == NULL) || |
| 2779 | (portp == NULL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2780 | return; |
| 2781 | |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 2782 | spin_lock_irqsave(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2783 | portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) || |
| 2784 | (portp->portnr < 8)) ? 0 : EREG_BANKSIZE); |
| 2785 | portp->uartaddr = (portp->portnr & 0x04) << 5; |
| 2786 | portp->pagenr = panelp->pagenr + (portp->portnr >> 3); |
| 2787 | |
| 2788 | BRDENABLE(portp->brdnr, portp->pagenr); |
| 2789 | stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03)); |
| 2790 | stl_cd1400setreg(portp, LIVR, (portp->portnr << 3)); |
| 2791 | portp->hwid = stl_cd1400getreg(portp, GFRCR); |
| 2792 | BRDDISABLE(portp->brdnr); |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 2793 | spin_unlock_irqrestore(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2794 | } |
| 2795 | |
| 2796 | /*****************************************************************************/ |
| 2797 | |
| 2798 | /* |
| 2799 | * Wait for the command register to be ready. We will poll this, |
| 2800 | * since it won't usually take too long to be ready. |
| 2801 | */ |
| 2802 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 2803 | static void stl_cd1400ccrwait(struct stlport *portp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2804 | { |
| 2805 | int i; |
| 2806 | |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 2807 | for (i = 0; i < CCR_MAXWAIT; i++) |
| 2808 | if (stl_cd1400getreg(portp, CCR) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2809 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2810 | |
| 2811 | printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%d\n", |
| 2812 | portp->portnr, portp->panelnr, portp->brdnr); |
| 2813 | } |
| 2814 | |
| 2815 | /*****************************************************************************/ |
| 2816 | |
| 2817 | /* |
| 2818 | * Set up the cd1400 registers for a port based on the termios port |
| 2819 | * settings. |
| 2820 | */ |
| 2821 | |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 2822 | static void stl_cd1400setport(struct stlport *portp, struct ktermios *tiosp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2823 | { |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 2824 | struct stlbrd *brdp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2825 | unsigned long flags; |
| 2826 | unsigned int clkdiv, baudrate; |
| 2827 | unsigned char cor1, cor2, cor3; |
| 2828 | unsigned char cor4, cor5, ccr; |
| 2829 | unsigned char srer, sreron, sreroff; |
| 2830 | unsigned char mcor1, mcor2, rtpr; |
| 2831 | unsigned char clk, div; |
| 2832 | |
| 2833 | cor1 = 0; |
| 2834 | cor2 = 0; |
| 2835 | cor3 = 0; |
| 2836 | cor4 = 0; |
| 2837 | cor5 = 0; |
| 2838 | ccr = 0; |
| 2839 | rtpr = 0; |
| 2840 | clk = 0; |
| 2841 | div = 0; |
| 2842 | mcor1 = 0; |
| 2843 | mcor2 = 0; |
| 2844 | sreron = 0; |
| 2845 | sreroff = 0; |
| 2846 | |
| 2847 | brdp = stl_brds[portp->brdnr]; |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 2848 | if (brdp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2849 | return; |
| 2850 | |
| 2851 | /* |
| 2852 | * Set up the RX char ignore mask with those RX error types we |
| 2853 | * can ignore. We can get the cd1400 to help us out a little here, |
| 2854 | * it will ignore parity errors and breaks for us. |
| 2855 | */ |
| 2856 | portp->rxignoremsk = 0; |
| 2857 | if (tiosp->c_iflag & IGNPAR) { |
| 2858 | portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN); |
| 2859 | cor1 |= COR1_PARIGNORE; |
| 2860 | } |
| 2861 | if (tiosp->c_iflag & IGNBRK) { |
| 2862 | portp->rxignoremsk |= ST_BREAK; |
| 2863 | cor4 |= COR4_IGNBRK; |
| 2864 | } |
| 2865 | |
| 2866 | portp->rxmarkmsk = ST_OVERRUN; |
| 2867 | if (tiosp->c_iflag & (INPCK | PARMRK)) |
| 2868 | portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING); |
| 2869 | if (tiosp->c_iflag & BRKINT) |
| 2870 | portp->rxmarkmsk |= ST_BREAK; |
| 2871 | |
| 2872 | /* |
| 2873 | * Go through the char size, parity and stop bits and set all the |
| 2874 | * option register appropriately. |
| 2875 | */ |
| 2876 | switch (tiosp->c_cflag & CSIZE) { |
| 2877 | case CS5: |
| 2878 | cor1 |= COR1_CHL5; |
| 2879 | break; |
| 2880 | case CS6: |
| 2881 | cor1 |= COR1_CHL6; |
| 2882 | break; |
| 2883 | case CS7: |
| 2884 | cor1 |= COR1_CHL7; |
| 2885 | break; |
| 2886 | default: |
| 2887 | cor1 |= COR1_CHL8; |
| 2888 | break; |
| 2889 | } |
| 2890 | |
| 2891 | if (tiosp->c_cflag & CSTOPB) |
| 2892 | cor1 |= COR1_STOP2; |
| 2893 | else |
| 2894 | cor1 |= COR1_STOP1; |
| 2895 | |
| 2896 | if (tiosp->c_cflag & PARENB) { |
| 2897 | if (tiosp->c_cflag & PARODD) |
| 2898 | cor1 |= (COR1_PARENB | COR1_PARODD); |
| 2899 | else |
| 2900 | cor1 |= (COR1_PARENB | COR1_PAREVEN); |
| 2901 | } else { |
| 2902 | cor1 |= COR1_PARNONE; |
| 2903 | } |
| 2904 | |
| 2905 | /* |
| 2906 | * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing |
| 2907 | * space for hardware flow control and the like. This should be set to |
| 2908 | * VMIN. Also here we will set the RX data timeout to 10ms - this should |
| 2909 | * really be based on VTIME. |
| 2910 | */ |
| 2911 | cor3 |= FIFO_RXTHRESHOLD; |
| 2912 | rtpr = 2; |
| 2913 | |
| 2914 | /* |
| 2915 | * Calculate the baud rate timers. For now we will just assume that |
| 2916 | * the input and output baud are the same. Could have used a baud |
| 2917 | * table here, but this way we can generate virtually any baud rate |
| 2918 | * we like! |
| 2919 | */ |
| 2920 | baudrate = tiosp->c_cflag & CBAUD; |
| 2921 | if (baudrate & CBAUDEX) { |
| 2922 | baudrate &= ~CBAUDEX; |
| 2923 | if ((baudrate < 1) || (baudrate > 4)) |
| 2924 | tiosp->c_cflag &= ~CBAUDEX; |
| 2925 | else |
| 2926 | baudrate += 15; |
| 2927 | } |
| 2928 | baudrate = stl_baudrates[baudrate]; |
| 2929 | if ((tiosp->c_cflag & CBAUD) == B38400) { |
Alan Cox | f8ae476 | 2008-07-16 21:56:37 +0100 | [diff] [blame] | 2930 | if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2931 | baudrate = 57600; |
Alan Cox | f8ae476 | 2008-07-16 21:56:37 +0100 | [diff] [blame] | 2932 | else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2933 | baudrate = 115200; |
Alan Cox | f8ae476 | 2008-07-16 21:56:37 +0100 | [diff] [blame] | 2934 | else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2935 | baudrate = 230400; |
Alan Cox | f8ae476 | 2008-07-16 21:56:37 +0100 | [diff] [blame] | 2936 | else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2937 | baudrate = 460800; |
Alan Cox | f8ae476 | 2008-07-16 21:56:37 +0100 | [diff] [blame] | 2938 | else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2939 | baudrate = (portp->baud_base / portp->custom_divisor); |
| 2940 | } |
| 2941 | if (baudrate > STL_CD1400MAXBAUD) |
| 2942 | baudrate = STL_CD1400MAXBAUD; |
| 2943 | |
| 2944 | if (baudrate > 0) { |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 2945 | for (clk = 0; clk < CD1400_NUMCLKS; clk++) { |
| 2946 | clkdiv = (portp->clk / stl_cd1400clkdivs[clk]) / baudrate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2947 | if (clkdiv < 0x100) |
| 2948 | break; |
| 2949 | } |
| 2950 | div = (unsigned char) clkdiv; |
| 2951 | } |
| 2952 | |
| 2953 | /* |
| 2954 | * Check what form of modem signaling is required and set it up. |
| 2955 | */ |
| 2956 | if ((tiosp->c_cflag & CLOCAL) == 0) { |
| 2957 | mcor1 |= MCOR1_DCD; |
| 2958 | mcor2 |= MCOR2_DCD; |
| 2959 | sreron |= SRER_MODEM; |
Alan Cox | f8ae476 | 2008-07-16 21:56:37 +0100 | [diff] [blame] | 2960 | portp->port.flags |= ASYNC_CHECK_CD; |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 2961 | } else |
Alan Cox | f8ae476 | 2008-07-16 21:56:37 +0100 | [diff] [blame] | 2962 | portp->port.flags &= ~ASYNC_CHECK_CD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2963 | |
| 2964 | /* |
| 2965 | * Setup cd1400 enhanced modes if we can. In particular we want to |
| 2966 | * handle as much of the flow control as possible automatically. As |
| 2967 | * well as saving a few CPU cycles it will also greatly improve flow |
| 2968 | * control reliability. |
| 2969 | */ |
| 2970 | if (tiosp->c_iflag & IXON) { |
| 2971 | cor2 |= COR2_TXIBE; |
| 2972 | cor3 |= COR3_SCD12; |
| 2973 | if (tiosp->c_iflag & IXANY) |
| 2974 | cor2 |= COR2_IXM; |
| 2975 | } |
| 2976 | |
| 2977 | if (tiosp->c_cflag & CRTSCTS) { |
| 2978 | cor2 |= COR2_CTSAE; |
| 2979 | mcor1 |= FIFO_RTSTHRESHOLD; |
| 2980 | } |
| 2981 | |
| 2982 | /* |
| 2983 | * All cd1400 register values calculated so go through and set |
| 2984 | * them all up. |
| 2985 | */ |
| 2986 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 2987 | pr_debug("SETPORT: portnr=%d panelnr=%d brdnr=%d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2988 | portp->portnr, portp->panelnr, portp->brdnr); |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 2989 | pr_debug(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2990 | cor1, cor2, cor3, cor4, cor5); |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 2991 | pr_debug(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2992 | mcor1, mcor2, rtpr, sreron, sreroff); |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 2993 | pr_debug(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div); |
| 2994 | pr_debug(" schr1=%x schr2=%x schr3=%x schr4=%x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2995 | tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP], |
| 2996 | tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2997 | |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 2998 | spin_lock_irqsave(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2999 | BRDENABLE(portp->brdnr, portp->pagenr); |
| 3000 | stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3)); |
| 3001 | srer = stl_cd1400getreg(portp, SRER); |
| 3002 | stl_cd1400setreg(portp, SRER, 0); |
| 3003 | if (stl_cd1400updatereg(portp, COR1, cor1)) |
| 3004 | ccr = 1; |
| 3005 | if (stl_cd1400updatereg(portp, COR2, cor2)) |
| 3006 | ccr = 1; |
| 3007 | if (stl_cd1400updatereg(portp, COR3, cor3)) |
| 3008 | ccr = 1; |
| 3009 | if (ccr) { |
| 3010 | stl_cd1400ccrwait(portp); |
| 3011 | stl_cd1400setreg(portp, CCR, CCR_CORCHANGE); |
| 3012 | } |
| 3013 | stl_cd1400setreg(portp, COR4, cor4); |
| 3014 | stl_cd1400setreg(portp, COR5, cor5); |
| 3015 | stl_cd1400setreg(portp, MCOR1, mcor1); |
| 3016 | stl_cd1400setreg(portp, MCOR2, mcor2); |
| 3017 | if (baudrate > 0) { |
| 3018 | stl_cd1400setreg(portp, TCOR, clk); |
| 3019 | stl_cd1400setreg(portp, TBPR, div); |
| 3020 | stl_cd1400setreg(portp, RCOR, clk); |
| 3021 | stl_cd1400setreg(portp, RBPR, div); |
| 3022 | } |
| 3023 | stl_cd1400setreg(portp, SCHR1, tiosp->c_cc[VSTART]); |
| 3024 | stl_cd1400setreg(portp, SCHR2, tiosp->c_cc[VSTOP]); |
| 3025 | stl_cd1400setreg(portp, SCHR3, tiosp->c_cc[VSTART]); |
| 3026 | stl_cd1400setreg(portp, SCHR4, tiosp->c_cc[VSTOP]); |
| 3027 | stl_cd1400setreg(portp, RTPR, rtpr); |
| 3028 | mcor1 = stl_cd1400getreg(portp, MSVR1); |
| 3029 | if (mcor1 & MSVR1_DCD) |
| 3030 | portp->sigs |= TIOCM_CD; |
| 3031 | else |
| 3032 | portp->sigs &= ~TIOCM_CD; |
| 3033 | stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron)); |
| 3034 | BRDDISABLE(portp->brdnr); |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 3035 | spin_unlock_irqrestore(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3036 | } |
| 3037 | |
| 3038 | /*****************************************************************************/ |
| 3039 | |
| 3040 | /* |
| 3041 | * Set the state of the DTR and RTS signals. |
| 3042 | */ |
| 3043 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 3044 | static void stl_cd1400setsignals(struct stlport *portp, int dtr, int rts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3045 | { |
| 3046 | unsigned char msvr1, msvr2; |
| 3047 | unsigned long flags; |
| 3048 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 3049 | pr_debug("stl_cd1400setsignals(portp=%p,dtr=%d,rts=%d)\n", |
| 3050 | portp, dtr, rts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3051 | |
| 3052 | msvr1 = 0; |
| 3053 | msvr2 = 0; |
| 3054 | if (dtr > 0) |
| 3055 | msvr1 = MSVR1_DTR; |
| 3056 | if (rts > 0) |
| 3057 | msvr2 = MSVR2_RTS; |
| 3058 | |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 3059 | spin_lock_irqsave(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3060 | BRDENABLE(portp->brdnr, portp->pagenr); |
| 3061 | stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03)); |
| 3062 | if (rts >= 0) |
| 3063 | stl_cd1400setreg(portp, MSVR2, msvr2); |
| 3064 | if (dtr >= 0) |
| 3065 | stl_cd1400setreg(portp, MSVR1, msvr1); |
| 3066 | BRDDISABLE(portp->brdnr); |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 3067 | spin_unlock_irqrestore(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3068 | } |
| 3069 | |
| 3070 | /*****************************************************************************/ |
| 3071 | |
| 3072 | /* |
| 3073 | * Return the state of the signals. |
| 3074 | */ |
| 3075 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 3076 | static int stl_cd1400getsignals(struct stlport *portp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3077 | { |
| 3078 | unsigned char msvr1, msvr2; |
| 3079 | unsigned long flags; |
| 3080 | int sigs; |
| 3081 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 3082 | pr_debug("stl_cd1400getsignals(portp=%p)\n", portp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3083 | |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 3084 | spin_lock_irqsave(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3085 | BRDENABLE(portp->brdnr, portp->pagenr); |
| 3086 | stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03)); |
| 3087 | msvr1 = stl_cd1400getreg(portp, MSVR1); |
| 3088 | msvr2 = stl_cd1400getreg(portp, MSVR2); |
| 3089 | BRDDISABLE(portp->brdnr); |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 3090 | spin_unlock_irqrestore(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3091 | |
| 3092 | sigs = 0; |
| 3093 | sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0; |
| 3094 | sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0; |
| 3095 | sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0; |
| 3096 | sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0; |
| 3097 | #if 0 |
| 3098 | sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0; |
| 3099 | sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0; |
| 3100 | #else |
| 3101 | sigs |= TIOCM_DSR; |
| 3102 | #endif |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 3103 | return sigs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3104 | } |
| 3105 | |
| 3106 | /*****************************************************************************/ |
| 3107 | |
| 3108 | /* |
| 3109 | * Enable/Disable the Transmitter and/or Receiver. |
| 3110 | */ |
| 3111 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 3112 | static void stl_cd1400enablerxtx(struct stlport *portp, int rx, int tx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3113 | { |
| 3114 | unsigned char ccr; |
| 3115 | unsigned long flags; |
| 3116 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 3117 | pr_debug("stl_cd1400enablerxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx); |
| 3118 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3119 | ccr = 0; |
| 3120 | |
| 3121 | if (tx == 0) |
| 3122 | ccr |= CCR_TXDISABLE; |
| 3123 | else if (tx > 0) |
| 3124 | ccr |= CCR_TXENABLE; |
| 3125 | if (rx == 0) |
| 3126 | ccr |= CCR_RXDISABLE; |
| 3127 | else if (rx > 0) |
| 3128 | ccr |= CCR_RXENABLE; |
| 3129 | |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 3130 | spin_lock_irqsave(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3131 | BRDENABLE(portp->brdnr, portp->pagenr); |
| 3132 | stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03)); |
| 3133 | stl_cd1400ccrwait(portp); |
| 3134 | stl_cd1400setreg(portp, CCR, ccr); |
| 3135 | stl_cd1400ccrwait(portp); |
| 3136 | BRDDISABLE(portp->brdnr); |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 3137 | spin_unlock_irqrestore(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3138 | } |
| 3139 | |
| 3140 | /*****************************************************************************/ |
| 3141 | |
| 3142 | /* |
| 3143 | * Start/stop the Transmitter and/or Receiver. |
| 3144 | */ |
| 3145 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 3146 | static void stl_cd1400startrxtx(struct stlport *portp, int rx, int tx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3147 | { |
| 3148 | unsigned char sreron, sreroff; |
| 3149 | unsigned long flags; |
| 3150 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 3151 | pr_debug("stl_cd1400startrxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3152 | |
| 3153 | sreron = 0; |
| 3154 | sreroff = 0; |
| 3155 | if (tx == 0) |
| 3156 | sreroff |= (SRER_TXDATA | SRER_TXEMPTY); |
| 3157 | else if (tx == 1) |
| 3158 | sreron |= SRER_TXDATA; |
| 3159 | else if (tx >= 2) |
| 3160 | sreron |= SRER_TXEMPTY; |
| 3161 | if (rx == 0) |
| 3162 | sreroff |= SRER_RXDATA; |
| 3163 | else if (rx > 0) |
| 3164 | sreron |= SRER_RXDATA; |
| 3165 | |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 3166 | spin_lock_irqsave(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3167 | BRDENABLE(portp->brdnr, portp->pagenr); |
| 3168 | stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03)); |
| 3169 | stl_cd1400setreg(portp, SRER, |
| 3170 | ((stl_cd1400getreg(portp, SRER) & ~sreroff) | sreron)); |
| 3171 | BRDDISABLE(portp->brdnr); |
| 3172 | if (tx > 0) |
| 3173 | set_bit(ASYI_TXBUSY, &portp->istate); |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 3174 | spin_unlock_irqrestore(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3175 | } |
| 3176 | |
| 3177 | /*****************************************************************************/ |
| 3178 | |
| 3179 | /* |
| 3180 | * Disable all interrupts from this port. |
| 3181 | */ |
| 3182 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 3183 | static void stl_cd1400disableintrs(struct stlport *portp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3184 | { |
| 3185 | unsigned long flags; |
| 3186 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 3187 | pr_debug("stl_cd1400disableintrs(portp=%p)\n", portp); |
| 3188 | |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 3189 | spin_lock_irqsave(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3190 | BRDENABLE(portp->brdnr, portp->pagenr); |
| 3191 | stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03)); |
| 3192 | stl_cd1400setreg(portp, SRER, 0); |
| 3193 | BRDDISABLE(portp->brdnr); |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 3194 | spin_unlock_irqrestore(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3195 | } |
| 3196 | |
| 3197 | /*****************************************************************************/ |
| 3198 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 3199 | static void stl_cd1400sendbreak(struct stlport *portp, int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3200 | { |
| 3201 | unsigned long flags; |
| 3202 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 3203 | pr_debug("stl_cd1400sendbreak(portp=%p,len=%d)\n", portp, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3204 | |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 3205 | spin_lock_irqsave(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3206 | BRDENABLE(portp->brdnr, portp->pagenr); |
| 3207 | stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03)); |
| 3208 | stl_cd1400setreg(portp, SRER, |
| 3209 | ((stl_cd1400getreg(portp, SRER) & ~SRER_TXDATA) | |
| 3210 | SRER_TXEMPTY)); |
| 3211 | BRDDISABLE(portp->brdnr); |
| 3212 | portp->brklen = len; |
| 3213 | if (len == 1) |
| 3214 | portp->stats.txbreaks++; |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 3215 | spin_unlock_irqrestore(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3216 | } |
| 3217 | |
| 3218 | /*****************************************************************************/ |
| 3219 | |
| 3220 | /* |
| 3221 | * Take flow control actions... |
| 3222 | */ |
| 3223 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 3224 | static void stl_cd1400flowctrl(struct stlport *portp, int state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3225 | { |
| 3226 | struct tty_struct *tty; |
| 3227 | unsigned long flags; |
| 3228 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 3229 | pr_debug("stl_cd1400flowctrl(portp=%p,state=%x)\n", portp, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3230 | |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 3231 | if (portp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3232 | return; |
Alan Cox | d18a750 | 2008-10-13 10:40:07 +0100 | [diff] [blame] | 3233 | tty = tty_port_tty_get(&portp->port); |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 3234 | if (tty == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3235 | return; |
| 3236 | |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 3237 | spin_lock_irqsave(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3238 | BRDENABLE(portp->brdnr, portp->pagenr); |
| 3239 | stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03)); |
| 3240 | |
| 3241 | if (state) { |
| 3242 | if (tty->termios->c_iflag & IXOFF) { |
| 3243 | stl_cd1400ccrwait(portp); |
| 3244 | stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1); |
| 3245 | portp->stats.rxxon++; |
| 3246 | stl_cd1400ccrwait(portp); |
| 3247 | } |
| 3248 | /* |
| 3249 | * Question: should we return RTS to what it was before? It may |
| 3250 | * have been set by an ioctl... Suppose not, since if you have |
| 3251 | * hardware flow control set then it is pretty silly to go and |
| 3252 | * set the RTS line by hand. |
| 3253 | */ |
| 3254 | if (tty->termios->c_cflag & CRTSCTS) { |
| 3255 | stl_cd1400setreg(portp, MCOR1, |
| 3256 | (stl_cd1400getreg(portp, MCOR1) | |
| 3257 | FIFO_RTSTHRESHOLD)); |
| 3258 | stl_cd1400setreg(portp, MSVR2, MSVR2_RTS); |
| 3259 | portp->stats.rxrtson++; |
| 3260 | } |
| 3261 | } else { |
| 3262 | if (tty->termios->c_iflag & IXOFF) { |
| 3263 | stl_cd1400ccrwait(portp); |
| 3264 | stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2); |
| 3265 | portp->stats.rxxoff++; |
| 3266 | stl_cd1400ccrwait(portp); |
| 3267 | } |
| 3268 | if (tty->termios->c_cflag & CRTSCTS) { |
| 3269 | stl_cd1400setreg(portp, MCOR1, |
| 3270 | (stl_cd1400getreg(portp, MCOR1) & 0xf0)); |
| 3271 | stl_cd1400setreg(portp, MSVR2, 0); |
| 3272 | portp->stats.rxrtsoff++; |
| 3273 | } |
| 3274 | } |
| 3275 | |
| 3276 | BRDDISABLE(portp->brdnr); |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 3277 | spin_unlock_irqrestore(&brd_lock, flags); |
Alan Cox | d18a750 | 2008-10-13 10:40:07 +0100 | [diff] [blame] | 3278 | tty_kref_put(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3279 | } |
| 3280 | |
| 3281 | /*****************************************************************************/ |
| 3282 | |
| 3283 | /* |
| 3284 | * Send a flow control character... |
| 3285 | */ |
| 3286 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 3287 | static void stl_cd1400sendflow(struct stlport *portp, int state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3288 | { |
| 3289 | struct tty_struct *tty; |
| 3290 | unsigned long flags; |
| 3291 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 3292 | pr_debug("stl_cd1400sendflow(portp=%p,state=%x)\n", portp, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3293 | |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 3294 | if (portp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3295 | return; |
Alan Cox | d18a750 | 2008-10-13 10:40:07 +0100 | [diff] [blame] | 3296 | tty = tty_port_tty_get(&portp->port); |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 3297 | if (tty == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3298 | return; |
| 3299 | |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 3300 | spin_lock_irqsave(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3301 | BRDENABLE(portp->brdnr, portp->pagenr); |
| 3302 | stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03)); |
| 3303 | if (state) { |
| 3304 | stl_cd1400ccrwait(portp); |
| 3305 | stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1); |
| 3306 | portp->stats.rxxon++; |
| 3307 | stl_cd1400ccrwait(portp); |
| 3308 | } else { |
| 3309 | stl_cd1400ccrwait(portp); |
| 3310 | stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2); |
| 3311 | portp->stats.rxxoff++; |
| 3312 | stl_cd1400ccrwait(portp); |
| 3313 | } |
| 3314 | BRDDISABLE(portp->brdnr); |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 3315 | spin_unlock_irqrestore(&brd_lock, flags); |
Alan Cox | d18a750 | 2008-10-13 10:40:07 +0100 | [diff] [blame] | 3316 | tty_kref_put(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3317 | } |
| 3318 | |
| 3319 | /*****************************************************************************/ |
| 3320 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 3321 | static void stl_cd1400flush(struct stlport *portp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3322 | { |
| 3323 | unsigned long flags; |
| 3324 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 3325 | pr_debug("stl_cd1400flush(portp=%p)\n", portp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3326 | |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 3327 | if (portp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3328 | return; |
| 3329 | |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 3330 | spin_lock_irqsave(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3331 | BRDENABLE(portp->brdnr, portp->pagenr); |
| 3332 | stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03)); |
| 3333 | stl_cd1400ccrwait(portp); |
| 3334 | stl_cd1400setreg(portp, CCR, CCR_TXFLUSHFIFO); |
| 3335 | stl_cd1400ccrwait(portp); |
| 3336 | portp->tx.tail = portp->tx.head; |
| 3337 | BRDDISABLE(portp->brdnr); |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 3338 | spin_unlock_irqrestore(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3339 | } |
| 3340 | |
| 3341 | /*****************************************************************************/ |
| 3342 | |
| 3343 | /* |
| 3344 | * Return the current state of data flow on this port. This is only |
| 3345 | * really interresting when determining if data has fully completed |
| 3346 | * transmission or not... This is easy for the cd1400, it accurately |
| 3347 | * maintains the busy port flag. |
| 3348 | */ |
| 3349 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 3350 | static int stl_cd1400datastate(struct stlport *portp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3351 | { |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 3352 | pr_debug("stl_cd1400datastate(portp=%p)\n", portp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3353 | |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 3354 | if (portp == NULL) |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 3355 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3356 | |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 3357 | return test_bit(ASYI_TXBUSY, &portp->istate) ? 1 : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3358 | } |
| 3359 | |
| 3360 | /*****************************************************************************/ |
| 3361 | |
| 3362 | /* |
| 3363 | * Interrupt service routine for cd1400 EasyIO boards. |
| 3364 | */ |
| 3365 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 3366 | static void stl_cd1400eiointr(struct stlpanel *panelp, unsigned int iobase) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3367 | { |
| 3368 | unsigned char svrtype; |
| 3369 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 3370 | pr_debug("stl_cd1400eiointr(panelp=%p,iobase=%x)\n", panelp, iobase); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3371 | |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 3372 | spin_lock(&brd_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3373 | outb(SVRR, iobase); |
| 3374 | svrtype = inb(iobase + EREG_DATA); |
| 3375 | if (panelp->nrports > 4) { |
| 3376 | outb((SVRR + 0x80), iobase); |
| 3377 | svrtype |= inb(iobase + EREG_DATA); |
| 3378 | } |
| 3379 | |
| 3380 | if (svrtype & SVRR_RX) |
| 3381 | stl_cd1400rxisr(panelp, iobase); |
| 3382 | else if (svrtype & SVRR_TX) |
| 3383 | stl_cd1400txisr(panelp, iobase); |
| 3384 | else if (svrtype & SVRR_MDM) |
| 3385 | stl_cd1400mdmisr(panelp, iobase); |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 3386 | |
| 3387 | spin_unlock(&brd_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3388 | } |
| 3389 | |
| 3390 | /*****************************************************************************/ |
| 3391 | |
| 3392 | /* |
| 3393 | * Interrupt service routine for cd1400 panels. |
| 3394 | */ |
| 3395 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 3396 | static void stl_cd1400echintr(struct stlpanel *panelp, unsigned int iobase) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3397 | { |
| 3398 | unsigned char svrtype; |
| 3399 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 3400 | pr_debug("stl_cd1400echintr(panelp=%p,iobase=%x)\n", panelp, iobase); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3401 | |
| 3402 | outb(SVRR, iobase); |
| 3403 | svrtype = inb(iobase + EREG_DATA); |
| 3404 | outb((SVRR + 0x80), iobase); |
| 3405 | svrtype |= inb(iobase + EREG_DATA); |
| 3406 | if (svrtype & SVRR_RX) |
| 3407 | stl_cd1400rxisr(panelp, iobase); |
| 3408 | else if (svrtype & SVRR_TX) |
| 3409 | stl_cd1400txisr(panelp, iobase); |
| 3410 | else if (svrtype & SVRR_MDM) |
| 3411 | stl_cd1400mdmisr(panelp, iobase); |
| 3412 | } |
| 3413 | |
| 3414 | |
| 3415 | /*****************************************************************************/ |
| 3416 | |
| 3417 | /* |
| 3418 | * Unfortunately we need to handle breaks in the TX data stream, since |
| 3419 | * this is the only way to generate them on the cd1400. |
| 3420 | */ |
| 3421 | |
Jiri Slaby | 60be481 | 2006-12-08 02:38:40 -0800 | [diff] [blame] | 3422 | static int stl_cd1400breakisr(struct stlport *portp, int ioaddr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3423 | { |
| 3424 | if (portp->brklen == 1) { |
| 3425 | outb((COR2 + portp->uartaddr), ioaddr); |
| 3426 | outb((inb(ioaddr + EREG_DATA) | COR2_ETC), |
| 3427 | (ioaddr + EREG_DATA)); |
| 3428 | outb((TDR + portp->uartaddr), ioaddr); |
| 3429 | outb(ETC_CMD, (ioaddr + EREG_DATA)); |
| 3430 | outb(ETC_STARTBREAK, (ioaddr + EREG_DATA)); |
| 3431 | outb((SRER + portp->uartaddr), ioaddr); |
| 3432 | outb((inb(ioaddr + EREG_DATA) & ~(SRER_TXDATA | SRER_TXEMPTY)), |
| 3433 | (ioaddr + EREG_DATA)); |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 3434 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3435 | } else if (portp->brklen > 1) { |
| 3436 | outb((TDR + portp->uartaddr), ioaddr); |
| 3437 | outb(ETC_CMD, (ioaddr + EREG_DATA)); |
| 3438 | outb(ETC_STOPBREAK, (ioaddr + EREG_DATA)); |
| 3439 | portp->brklen = -1; |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 3440 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3441 | } else { |
| 3442 | outb((COR2 + portp->uartaddr), ioaddr); |
| 3443 | outb((inb(ioaddr + EREG_DATA) & ~COR2_ETC), |
| 3444 | (ioaddr + EREG_DATA)); |
| 3445 | portp->brklen = 0; |
| 3446 | } |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 3447 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3448 | } |
| 3449 | |
| 3450 | /*****************************************************************************/ |
| 3451 | |
| 3452 | /* |
| 3453 | * Transmit interrupt handler. This has gotta be fast! Handling TX |
| 3454 | * chars is pretty simple, stuff as many as possible from the TX buffer |
| 3455 | * into the cd1400 FIFO. Must also handle TX breaks here, since they |
| 3456 | * are embedded as commands in the data stream. Oh no, had to use a goto! |
| 3457 | * This could be optimized more, will do when I get time... |
| 3458 | * In practice it is possible that interrupts are enabled but that the |
| 3459 | * port has been hung up. Need to handle not having any TX buffer here, |
| 3460 | * this is done by using the side effect that head and tail will also |
| 3461 | * be NULL if the buffer has been freed. |
| 3462 | */ |
| 3463 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 3464 | static void stl_cd1400txisr(struct stlpanel *panelp, int ioaddr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3465 | { |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 3466 | struct stlport *portp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3467 | int len, stlen; |
| 3468 | char *head, *tail; |
| 3469 | unsigned char ioack, srer; |
Alan Cox | d18a750 | 2008-10-13 10:40:07 +0100 | [diff] [blame] | 3470 | struct tty_struct *tty; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3471 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 3472 | pr_debug("stl_cd1400txisr(panelp=%p,ioaddr=%x)\n", panelp, ioaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3473 | |
| 3474 | ioack = inb(ioaddr + EREG_TXACK); |
| 3475 | if (((ioack & panelp->ackmask) != 0) || |
| 3476 | ((ioack & ACK_TYPMASK) != ACK_TYPTX)) { |
| 3477 | printk("STALLION: bad TX interrupt ack value=%x\n", ioack); |
| 3478 | return; |
| 3479 | } |
| 3480 | portp = panelp->ports[(ioack >> 3)]; |
| 3481 | |
| 3482 | /* |
| 3483 | * Unfortunately we need to handle breaks in the data stream, since |
| 3484 | * this is the only way to generate them on the cd1400. Do it now if |
| 3485 | * a break is to be sent. |
| 3486 | */ |
| 3487 | if (portp->brklen != 0) |
| 3488 | if (stl_cd1400breakisr(portp, ioaddr)) |
| 3489 | goto stl_txalldone; |
| 3490 | |
| 3491 | head = portp->tx.head; |
| 3492 | tail = portp->tx.tail; |
| 3493 | len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head)); |
| 3494 | if ((len == 0) || ((len < STL_TXBUFLOW) && |
| 3495 | (test_bit(ASYI_TXLOW, &portp->istate) == 0))) { |
| 3496 | set_bit(ASYI_TXLOW, &portp->istate); |
Alan Cox | d18a750 | 2008-10-13 10:40:07 +0100 | [diff] [blame] | 3497 | tty = tty_port_tty_get(&portp->port); |
| 3498 | if (tty) { |
| 3499 | tty_wakeup(tty); |
| 3500 | tty_kref_put(tty); |
| 3501 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3502 | } |
| 3503 | |
| 3504 | if (len == 0) { |
| 3505 | outb((SRER + portp->uartaddr), ioaddr); |
| 3506 | srer = inb(ioaddr + EREG_DATA); |
| 3507 | if (srer & SRER_TXDATA) { |
| 3508 | srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY; |
| 3509 | } else { |
| 3510 | srer &= ~(SRER_TXDATA | SRER_TXEMPTY); |
| 3511 | clear_bit(ASYI_TXBUSY, &portp->istate); |
| 3512 | } |
| 3513 | outb(srer, (ioaddr + EREG_DATA)); |
| 3514 | } else { |
Jiri Slaby | 843b568 | 2006-12-08 02:39:12 -0800 | [diff] [blame] | 3515 | len = min(len, CD1400_TXFIFOSIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3516 | portp->stats.txtotal += len; |
Jiri Slaby | 319fe7c | 2008-02-07 00:16:36 -0800 | [diff] [blame] | 3517 | stlen = min_t(unsigned int, len, |
| 3518 | (portp->tx.buf + STL_TXBUFSIZE) - tail); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3519 | outb((TDR + portp->uartaddr), ioaddr); |
| 3520 | outsb((ioaddr + EREG_DATA), tail, stlen); |
| 3521 | len -= stlen; |
| 3522 | tail += stlen; |
| 3523 | if (tail >= (portp->tx.buf + STL_TXBUFSIZE)) |
| 3524 | tail = portp->tx.buf; |
| 3525 | if (len > 0) { |
| 3526 | outsb((ioaddr + EREG_DATA), tail, len); |
| 3527 | tail += len; |
| 3528 | } |
| 3529 | portp->tx.tail = tail; |
| 3530 | } |
| 3531 | |
| 3532 | stl_txalldone: |
| 3533 | outb((EOSRR + portp->uartaddr), ioaddr); |
| 3534 | outb(0, (ioaddr + EREG_DATA)); |
| 3535 | } |
| 3536 | |
| 3537 | /*****************************************************************************/ |
| 3538 | |
| 3539 | /* |
| 3540 | * Receive character interrupt handler. Determine if we have good chars |
| 3541 | * or bad chars and then process appropriately. Good chars are easy |
| 3542 | * just shove the lot into the RX buffer and set all status byte to 0. |
| 3543 | * If a bad RX char then process as required. This routine needs to be |
| 3544 | * fast! In practice it is possible that we get an interrupt on a port |
| 3545 | * that is closed. This can happen on hangups - since they completely |
| 3546 | * shutdown a port not in user context. Need to handle this case. |
| 3547 | */ |
| 3548 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 3549 | static void stl_cd1400rxisr(struct stlpanel *panelp, int ioaddr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3550 | { |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 3551 | struct stlport *portp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3552 | struct tty_struct *tty; |
| 3553 | unsigned int ioack, len, buflen; |
| 3554 | unsigned char status; |
| 3555 | char ch; |
| 3556 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 3557 | pr_debug("stl_cd1400rxisr(panelp=%p,ioaddr=%x)\n", panelp, ioaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3558 | |
| 3559 | ioack = inb(ioaddr + EREG_RXACK); |
| 3560 | if ((ioack & panelp->ackmask) != 0) { |
| 3561 | printk("STALLION: bad RX interrupt ack value=%x\n", ioack); |
| 3562 | return; |
| 3563 | } |
| 3564 | portp = panelp->ports[(ioack >> 3)]; |
Alan Cox | d18a750 | 2008-10-13 10:40:07 +0100 | [diff] [blame] | 3565 | tty = tty_port_tty_get(&portp->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3566 | |
| 3567 | if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) { |
| 3568 | outb((RDCR + portp->uartaddr), ioaddr); |
| 3569 | len = inb(ioaddr + EREG_DATA); |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 3570 | if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) { |
Jiri Slaby | 319fe7c | 2008-02-07 00:16:36 -0800 | [diff] [blame] | 3571 | len = min_t(unsigned int, len, sizeof(stl_unwanted)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3572 | outb((RDSR + portp->uartaddr), ioaddr); |
| 3573 | insb((ioaddr + EREG_DATA), &stl_unwanted[0], len); |
| 3574 | portp->stats.rxlost += len; |
| 3575 | portp->stats.rxtotal += len; |
| 3576 | } else { |
Jiri Slaby | 843b568 | 2006-12-08 02:39:12 -0800 | [diff] [blame] | 3577 | len = min(len, buflen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3578 | if (len > 0) { |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 3579 | unsigned char *ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3580 | outb((RDSR + portp->uartaddr), ioaddr); |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 3581 | tty_prepare_flip_string(tty, &ptr, len); |
| 3582 | insb((ioaddr + EREG_DATA), ptr, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3583 | tty_schedule_flip(tty); |
| 3584 | portp->stats.rxtotal += len; |
| 3585 | } |
| 3586 | } |
| 3587 | } else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) { |
| 3588 | outb((RDSR + portp->uartaddr), ioaddr); |
| 3589 | status = inb(ioaddr + EREG_DATA); |
| 3590 | ch = inb(ioaddr + EREG_DATA); |
| 3591 | if (status & ST_PARITY) |
| 3592 | portp->stats.rxparity++; |
| 3593 | if (status & ST_FRAMING) |
| 3594 | portp->stats.rxframing++; |
| 3595 | if (status & ST_OVERRUN) |
| 3596 | portp->stats.rxoverrun++; |
| 3597 | if (status & ST_BREAK) |
| 3598 | portp->stats.rxbreaks++; |
| 3599 | if (status & ST_SCHARMASK) { |
| 3600 | if ((status & ST_SCHARMASK) == ST_SCHAR1) |
| 3601 | portp->stats.txxon++; |
| 3602 | if ((status & ST_SCHARMASK) == ST_SCHAR2) |
| 3603 | portp->stats.txxoff++; |
| 3604 | goto stl_rxalldone; |
| 3605 | } |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 3606 | if (tty != NULL && (portp->rxignoremsk & status) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3607 | if (portp->rxmarkmsk & status) { |
| 3608 | if (status & ST_BREAK) { |
| 3609 | status = TTY_BREAK; |
Alan Cox | f8ae476 | 2008-07-16 21:56:37 +0100 | [diff] [blame] | 3610 | if (portp->port.flags & ASYNC_SAK) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3611 | do_SAK(tty); |
| 3612 | BRDENABLE(portp->brdnr, portp->pagenr); |
| 3613 | } |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 3614 | } else if (status & ST_PARITY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3615 | status = TTY_PARITY; |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 3616 | else if (status & ST_FRAMING) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3617 | status = TTY_FRAME; |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 3618 | else if(status & ST_OVERRUN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3619 | status = TTY_OVERRUN; |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 3620 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3621 | status = 0; |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 3622 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3623 | status = 0; |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 3624 | tty_insert_flip_char(tty, ch, status); |
| 3625 | tty_schedule_flip(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3626 | } |
| 3627 | } else { |
| 3628 | printk("STALLION: bad RX interrupt ack value=%x\n", ioack); |
Alan Cox | d18a750 | 2008-10-13 10:40:07 +0100 | [diff] [blame] | 3629 | tty_kref_put(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3630 | return; |
| 3631 | } |
| 3632 | |
| 3633 | stl_rxalldone: |
Alan Cox | d18a750 | 2008-10-13 10:40:07 +0100 | [diff] [blame] | 3634 | tty_kref_put(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3635 | outb((EOSRR + portp->uartaddr), ioaddr); |
| 3636 | outb(0, (ioaddr + EREG_DATA)); |
| 3637 | } |
| 3638 | |
| 3639 | /*****************************************************************************/ |
| 3640 | |
| 3641 | /* |
| 3642 | * Modem interrupt handler. The is called when the modem signal line |
| 3643 | * (DCD) has changed state. Leave most of the work to the off-level |
| 3644 | * processing routine. |
| 3645 | */ |
| 3646 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 3647 | static void stl_cd1400mdmisr(struct stlpanel *panelp, int ioaddr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3648 | { |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 3649 | struct stlport *portp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3650 | unsigned int ioack; |
| 3651 | unsigned char misr; |
| 3652 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 3653 | pr_debug("stl_cd1400mdmisr(panelp=%p)\n", panelp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3654 | |
| 3655 | ioack = inb(ioaddr + EREG_MDACK); |
| 3656 | if (((ioack & panelp->ackmask) != 0) || |
| 3657 | ((ioack & ACK_TYPMASK) != ACK_TYPMDM)) { |
| 3658 | printk("STALLION: bad MODEM interrupt ack value=%x\n", ioack); |
| 3659 | return; |
| 3660 | } |
| 3661 | portp = panelp->ports[(ioack >> 3)]; |
| 3662 | |
| 3663 | outb((MISR + portp->uartaddr), ioaddr); |
| 3664 | misr = inb(ioaddr + EREG_DATA); |
| 3665 | if (misr & MISR_DCD) { |
Jiri Slaby | ccfea3c | 2008-02-07 00:16:39 -0800 | [diff] [blame] | 3666 | stl_cd_change(portp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3667 | portp->stats.modem++; |
| 3668 | } |
| 3669 | |
| 3670 | outb((EOSRR + portp->uartaddr), ioaddr); |
| 3671 | outb(0, (ioaddr + EREG_DATA)); |
| 3672 | } |
| 3673 | |
| 3674 | /*****************************************************************************/ |
| 3675 | /* SC26198 HARDWARE FUNCTIONS */ |
| 3676 | /*****************************************************************************/ |
| 3677 | |
| 3678 | /* |
| 3679 | * These functions get/set/update the registers of the sc26198 UARTs. |
| 3680 | * Access to the sc26198 registers is via an address/data io port pair. |
| 3681 | * (Maybe should make this inline...) |
| 3682 | */ |
| 3683 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 3684 | static int stl_sc26198getreg(struct stlport *portp, int regnr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3685 | { |
| 3686 | outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR)); |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 3687 | return inb(portp->ioaddr + XP_DATA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3688 | } |
| 3689 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 3690 | static void stl_sc26198setreg(struct stlport *portp, int regnr, int value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3691 | { |
| 3692 | outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR)); |
| 3693 | outb(value, (portp->ioaddr + XP_DATA)); |
| 3694 | } |
| 3695 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 3696 | static int stl_sc26198updatereg(struct stlport *portp, int regnr, int value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3697 | { |
| 3698 | outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR)); |
| 3699 | if (inb(portp->ioaddr + XP_DATA) != value) { |
| 3700 | outb(value, (portp->ioaddr + XP_DATA)); |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 3701 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3702 | } |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 3703 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3704 | } |
| 3705 | |
| 3706 | /*****************************************************************************/ |
| 3707 | |
| 3708 | /* |
| 3709 | * Functions to get and set the sc26198 global registers. |
| 3710 | */ |
| 3711 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 3712 | static int stl_sc26198getglobreg(struct stlport *portp, int regnr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3713 | { |
| 3714 | outb(regnr, (portp->ioaddr + XP_ADDR)); |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 3715 | return inb(portp->ioaddr + XP_DATA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3716 | } |
| 3717 | |
| 3718 | #if 0 |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 3719 | static void stl_sc26198setglobreg(struct stlport *portp, int regnr, int value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3720 | { |
| 3721 | outb(regnr, (portp->ioaddr + XP_ADDR)); |
| 3722 | outb(value, (portp->ioaddr + XP_DATA)); |
| 3723 | } |
| 3724 | #endif |
| 3725 | |
| 3726 | /*****************************************************************************/ |
| 3727 | |
| 3728 | /* |
| 3729 | * Inbitialize the UARTs in a panel. We don't care what sort of board |
| 3730 | * these ports are on - since the port io registers are almost |
| 3731 | * identical when dealing with ports. |
| 3732 | */ |
| 3733 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 3734 | static int stl_sc26198panelinit(struct stlbrd *brdp, struct stlpanel *panelp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3735 | { |
| 3736 | int chipmask, i; |
| 3737 | int nrchips, ioaddr; |
| 3738 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 3739 | pr_debug("stl_sc26198panelinit(brdp=%p,panelp=%p)\n", brdp, panelp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3740 | |
| 3741 | BRDENABLE(panelp->brdnr, panelp->pagenr); |
| 3742 | |
| 3743 | /* |
| 3744 | * Check that each chip is present and started up OK. |
| 3745 | */ |
| 3746 | chipmask = 0; |
| 3747 | nrchips = (panelp->nrports + 4) / SC26198_PORTS; |
| 3748 | if (brdp->brdtype == BRD_ECHPCI) |
| 3749 | outb(panelp->pagenr, brdp->ioctrl); |
| 3750 | |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 3751 | for (i = 0; i < nrchips; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3752 | ioaddr = panelp->iobase + (i * 4); |
| 3753 | outb(SCCR, (ioaddr + XP_ADDR)); |
| 3754 | outb(CR_RESETALL, (ioaddr + XP_DATA)); |
| 3755 | outb(TSTR, (ioaddr + XP_ADDR)); |
| 3756 | if (inb(ioaddr + XP_DATA) != 0) { |
| 3757 | printk("STALLION: sc26198 not responding, " |
| 3758 | "brd=%d panel=%d chip=%d\n", |
| 3759 | panelp->brdnr, panelp->panelnr, i); |
| 3760 | continue; |
| 3761 | } |
| 3762 | chipmask |= (0x1 << i); |
| 3763 | outb(GCCR, (ioaddr + XP_ADDR)); |
| 3764 | outb(GCCR_IVRTYPCHANACK, (ioaddr + XP_DATA)); |
| 3765 | outb(WDTRCR, (ioaddr + XP_ADDR)); |
| 3766 | outb(0xff, (ioaddr + XP_DATA)); |
| 3767 | } |
| 3768 | |
| 3769 | BRDDISABLE(panelp->brdnr); |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 3770 | return chipmask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3771 | } |
| 3772 | |
| 3773 | /*****************************************************************************/ |
| 3774 | |
| 3775 | /* |
| 3776 | * Initialize hardware specific port registers. |
| 3777 | */ |
| 3778 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 3779 | static void stl_sc26198portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3780 | { |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 3781 | pr_debug("stl_sc26198portinit(brdp=%p,panelp=%p,portp=%p)\n", brdp, |
| 3782 | panelp, portp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3783 | |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 3784 | if ((brdp == NULL) || (panelp == NULL) || |
| 3785 | (portp == NULL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3786 | return; |
| 3787 | |
| 3788 | portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4); |
| 3789 | portp->uartaddr = (portp->portnr & 0x07) << 4; |
| 3790 | portp->pagenr = panelp->pagenr; |
| 3791 | portp->hwid = 0x1; |
| 3792 | |
| 3793 | BRDENABLE(portp->brdnr, portp->pagenr); |
| 3794 | stl_sc26198setreg(portp, IOPCR, IOPCR_SETSIGS); |
| 3795 | BRDDISABLE(portp->brdnr); |
| 3796 | } |
| 3797 | |
| 3798 | /*****************************************************************************/ |
| 3799 | |
| 3800 | /* |
| 3801 | * Set up the sc26198 registers for a port based on the termios port |
| 3802 | * settings. |
| 3803 | */ |
| 3804 | |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 3805 | static void stl_sc26198setport(struct stlport *portp, struct ktermios *tiosp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3806 | { |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 3807 | struct stlbrd *brdp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3808 | unsigned long flags; |
| 3809 | unsigned int baudrate; |
| 3810 | unsigned char mr0, mr1, mr2, clk; |
| 3811 | unsigned char imron, imroff, iopr, ipr; |
| 3812 | |
| 3813 | mr0 = 0; |
| 3814 | mr1 = 0; |
| 3815 | mr2 = 0; |
| 3816 | clk = 0; |
| 3817 | iopr = 0; |
| 3818 | imron = 0; |
| 3819 | imroff = 0; |
| 3820 | |
| 3821 | brdp = stl_brds[portp->brdnr]; |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 3822 | if (brdp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3823 | return; |
| 3824 | |
| 3825 | /* |
| 3826 | * Set up the RX char ignore mask with those RX error types we |
| 3827 | * can ignore. |
| 3828 | */ |
| 3829 | portp->rxignoremsk = 0; |
| 3830 | if (tiosp->c_iflag & IGNPAR) |
| 3831 | portp->rxignoremsk |= (SR_RXPARITY | SR_RXFRAMING | |
| 3832 | SR_RXOVERRUN); |
| 3833 | if (tiosp->c_iflag & IGNBRK) |
| 3834 | portp->rxignoremsk |= SR_RXBREAK; |
| 3835 | |
| 3836 | portp->rxmarkmsk = SR_RXOVERRUN; |
| 3837 | if (tiosp->c_iflag & (INPCK | PARMRK)) |
| 3838 | portp->rxmarkmsk |= (SR_RXPARITY | SR_RXFRAMING); |
| 3839 | if (tiosp->c_iflag & BRKINT) |
| 3840 | portp->rxmarkmsk |= SR_RXBREAK; |
| 3841 | |
| 3842 | /* |
| 3843 | * Go through the char size, parity and stop bits and set all the |
| 3844 | * option register appropriately. |
| 3845 | */ |
| 3846 | switch (tiosp->c_cflag & CSIZE) { |
| 3847 | case CS5: |
| 3848 | mr1 |= MR1_CS5; |
| 3849 | break; |
| 3850 | case CS6: |
| 3851 | mr1 |= MR1_CS6; |
| 3852 | break; |
| 3853 | case CS7: |
| 3854 | mr1 |= MR1_CS7; |
| 3855 | break; |
| 3856 | default: |
| 3857 | mr1 |= MR1_CS8; |
| 3858 | break; |
| 3859 | } |
| 3860 | |
| 3861 | if (tiosp->c_cflag & CSTOPB) |
| 3862 | mr2 |= MR2_STOP2; |
| 3863 | else |
| 3864 | mr2 |= MR2_STOP1; |
| 3865 | |
| 3866 | if (tiosp->c_cflag & PARENB) { |
| 3867 | if (tiosp->c_cflag & PARODD) |
| 3868 | mr1 |= (MR1_PARENB | MR1_PARODD); |
| 3869 | else |
| 3870 | mr1 |= (MR1_PARENB | MR1_PAREVEN); |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 3871 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3872 | mr1 |= MR1_PARNONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3873 | |
| 3874 | mr1 |= MR1_ERRBLOCK; |
| 3875 | |
| 3876 | /* |
| 3877 | * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing |
| 3878 | * space for hardware flow control and the like. This should be set to |
| 3879 | * VMIN. |
| 3880 | */ |
| 3881 | mr2 |= MR2_RXFIFOHALF; |
| 3882 | |
| 3883 | /* |
| 3884 | * Calculate the baud rate timers. For now we will just assume that |
| 3885 | * the input and output baud are the same. The sc26198 has a fixed |
| 3886 | * baud rate table, so only discrete baud rates possible. |
| 3887 | */ |
| 3888 | baudrate = tiosp->c_cflag & CBAUD; |
| 3889 | if (baudrate & CBAUDEX) { |
| 3890 | baudrate &= ~CBAUDEX; |
| 3891 | if ((baudrate < 1) || (baudrate > 4)) |
| 3892 | tiosp->c_cflag &= ~CBAUDEX; |
| 3893 | else |
| 3894 | baudrate += 15; |
| 3895 | } |
| 3896 | baudrate = stl_baudrates[baudrate]; |
| 3897 | if ((tiosp->c_cflag & CBAUD) == B38400) { |
Alan Cox | f8ae476 | 2008-07-16 21:56:37 +0100 | [diff] [blame] | 3898 | if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3899 | baudrate = 57600; |
Alan Cox | f8ae476 | 2008-07-16 21:56:37 +0100 | [diff] [blame] | 3900 | else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3901 | baudrate = 115200; |
Alan Cox | f8ae476 | 2008-07-16 21:56:37 +0100 | [diff] [blame] | 3902 | else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3903 | baudrate = 230400; |
Alan Cox | f8ae476 | 2008-07-16 21:56:37 +0100 | [diff] [blame] | 3904 | else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3905 | baudrate = 460800; |
Alan Cox | f8ae476 | 2008-07-16 21:56:37 +0100 | [diff] [blame] | 3906 | else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3907 | baudrate = (portp->baud_base / portp->custom_divisor); |
| 3908 | } |
| 3909 | if (baudrate > STL_SC26198MAXBAUD) |
| 3910 | baudrate = STL_SC26198MAXBAUD; |
| 3911 | |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 3912 | if (baudrate > 0) |
| 3913 | for (clk = 0; clk < SC26198_NRBAUDS; clk++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3914 | if (baudrate <= sc26198_baudtable[clk]) |
| 3915 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3916 | |
| 3917 | /* |
| 3918 | * Check what form of modem signaling is required and set it up. |
| 3919 | */ |
| 3920 | if (tiosp->c_cflag & CLOCAL) { |
Alan Cox | f8ae476 | 2008-07-16 21:56:37 +0100 | [diff] [blame] | 3921 | portp->port.flags &= ~ASYNC_CHECK_CD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3922 | } else { |
| 3923 | iopr |= IOPR_DCDCOS; |
| 3924 | imron |= IR_IOPORT; |
Alan Cox | f8ae476 | 2008-07-16 21:56:37 +0100 | [diff] [blame] | 3925 | portp->port.flags |= ASYNC_CHECK_CD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3926 | } |
| 3927 | |
| 3928 | /* |
| 3929 | * Setup sc26198 enhanced modes if we can. In particular we want to |
| 3930 | * handle as much of the flow control as possible automatically. As |
| 3931 | * well as saving a few CPU cycles it will also greatly improve flow |
| 3932 | * control reliability. |
| 3933 | */ |
| 3934 | if (tiosp->c_iflag & IXON) { |
| 3935 | mr0 |= MR0_SWFTX | MR0_SWFT; |
| 3936 | imron |= IR_XONXOFF; |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 3937 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3938 | imroff |= IR_XONXOFF; |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 3939 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3940 | if (tiosp->c_iflag & IXOFF) |
| 3941 | mr0 |= MR0_SWFRX; |
| 3942 | |
| 3943 | if (tiosp->c_cflag & CRTSCTS) { |
| 3944 | mr2 |= MR2_AUTOCTS; |
| 3945 | mr1 |= MR1_AUTORTS; |
| 3946 | } |
| 3947 | |
| 3948 | /* |
| 3949 | * All sc26198 register values calculated so go through and set |
| 3950 | * them all up. |
| 3951 | */ |
| 3952 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 3953 | pr_debug("SETPORT: portnr=%d panelnr=%d brdnr=%d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3954 | portp->portnr, portp->panelnr, portp->brdnr); |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 3955 | pr_debug(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk); |
| 3956 | pr_debug(" iopr=%x imron=%x imroff=%x\n", iopr, imron, imroff); |
| 3957 | pr_debug(" schr1=%x schr2=%x schr3=%x schr4=%x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3958 | tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP], |
| 3959 | tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3960 | |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 3961 | spin_lock_irqsave(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3962 | BRDENABLE(portp->brdnr, portp->pagenr); |
| 3963 | stl_sc26198setreg(portp, IMR, 0); |
| 3964 | stl_sc26198updatereg(portp, MR0, mr0); |
| 3965 | stl_sc26198updatereg(portp, MR1, mr1); |
| 3966 | stl_sc26198setreg(portp, SCCR, CR_RXERRBLOCK); |
| 3967 | stl_sc26198updatereg(portp, MR2, mr2); |
| 3968 | stl_sc26198updatereg(portp, IOPIOR, |
| 3969 | ((stl_sc26198getreg(portp, IOPIOR) & ~IPR_CHANGEMASK) | iopr)); |
| 3970 | |
| 3971 | if (baudrate > 0) { |
| 3972 | stl_sc26198setreg(portp, TXCSR, clk); |
| 3973 | stl_sc26198setreg(portp, RXCSR, clk); |
| 3974 | } |
| 3975 | |
| 3976 | stl_sc26198setreg(portp, XONCR, tiosp->c_cc[VSTART]); |
| 3977 | stl_sc26198setreg(portp, XOFFCR, tiosp->c_cc[VSTOP]); |
| 3978 | |
| 3979 | ipr = stl_sc26198getreg(portp, IPR); |
| 3980 | if (ipr & IPR_DCD) |
| 3981 | portp->sigs &= ~TIOCM_CD; |
| 3982 | else |
| 3983 | portp->sigs |= TIOCM_CD; |
| 3984 | |
| 3985 | portp->imr = (portp->imr & ~imroff) | imron; |
| 3986 | stl_sc26198setreg(portp, IMR, portp->imr); |
| 3987 | BRDDISABLE(portp->brdnr); |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 3988 | spin_unlock_irqrestore(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3989 | } |
| 3990 | |
| 3991 | /*****************************************************************************/ |
| 3992 | |
| 3993 | /* |
| 3994 | * Set the state of the DTR and RTS signals. |
| 3995 | */ |
| 3996 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 3997 | static void stl_sc26198setsignals(struct stlport *portp, int dtr, int rts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3998 | { |
| 3999 | unsigned char iopioron, iopioroff; |
| 4000 | unsigned long flags; |
| 4001 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 4002 | pr_debug("stl_sc26198setsignals(portp=%p,dtr=%d,rts=%d)\n", portp, |
| 4003 | dtr, rts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4004 | |
| 4005 | iopioron = 0; |
| 4006 | iopioroff = 0; |
| 4007 | if (dtr == 0) |
| 4008 | iopioroff |= IPR_DTR; |
| 4009 | else if (dtr > 0) |
| 4010 | iopioron |= IPR_DTR; |
| 4011 | if (rts == 0) |
| 4012 | iopioroff |= IPR_RTS; |
| 4013 | else if (rts > 0) |
| 4014 | iopioron |= IPR_RTS; |
| 4015 | |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 4016 | spin_lock_irqsave(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4017 | BRDENABLE(portp->brdnr, portp->pagenr); |
| 4018 | stl_sc26198setreg(portp, IOPIOR, |
| 4019 | ((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron)); |
| 4020 | BRDDISABLE(portp->brdnr); |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 4021 | spin_unlock_irqrestore(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4022 | } |
| 4023 | |
| 4024 | /*****************************************************************************/ |
| 4025 | |
| 4026 | /* |
| 4027 | * Return the state of the signals. |
| 4028 | */ |
| 4029 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 4030 | static int stl_sc26198getsignals(struct stlport *portp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4031 | { |
| 4032 | unsigned char ipr; |
| 4033 | unsigned long flags; |
| 4034 | int sigs; |
| 4035 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 4036 | pr_debug("stl_sc26198getsignals(portp=%p)\n", portp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4037 | |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 4038 | spin_lock_irqsave(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4039 | BRDENABLE(portp->brdnr, portp->pagenr); |
| 4040 | ipr = stl_sc26198getreg(portp, IPR); |
| 4041 | BRDDISABLE(portp->brdnr); |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 4042 | spin_unlock_irqrestore(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4043 | |
| 4044 | sigs = 0; |
| 4045 | sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD; |
| 4046 | sigs |= (ipr & IPR_CTS) ? 0 : TIOCM_CTS; |
| 4047 | sigs |= (ipr & IPR_DTR) ? 0: TIOCM_DTR; |
| 4048 | sigs |= (ipr & IPR_RTS) ? 0: TIOCM_RTS; |
| 4049 | sigs |= TIOCM_DSR; |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 4050 | return sigs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4051 | } |
| 4052 | |
| 4053 | /*****************************************************************************/ |
| 4054 | |
| 4055 | /* |
| 4056 | * Enable/Disable the Transmitter and/or Receiver. |
| 4057 | */ |
| 4058 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 4059 | static void stl_sc26198enablerxtx(struct stlport *portp, int rx, int tx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4060 | { |
| 4061 | unsigned char ccr; |
| 4062 | unsigned long flags; |
| 4063 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 4064 | pr_debug("stl_sc26198enablerxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx,tx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4065 | |
| 4066 | ccr = portp->crenable; |
| 4067 | if (tx == 0) |
| 4068 | ccr &= ~CR_TXENABLE; |
| 4069 | else if (tx > 0) |
| 4070 | ccr |= CR_TXENABLE; |
| 4071 | if (rx == 0) |
| 4072 | ccr &= ~CR_RXENABLE; |
| 4073 | else if (rx > 0) |
| 4074 | ccr |= CR_RXENABLE; |
| 4075 | |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 4076 | spin_lock_irqsave(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4077 | BRDENABLE(portp->brdnr, portp->pagenr); |
| 4078 | stl_sc26198setreg(portp, SCCR, ccr); |
| 4079 | BRDDISABLE(portp->brdnr); |
| 4080 | portp->crenable = ccr; |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 4081 | spin_unlock_irqrestore(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4082 | } |
| 4083 | |
| 4084 | /*****************************************************************************/ |
| 4085 | |
| 4086 | /* |
| 4087 | * Start/stop the Transmitter and/or Receiver. |
| 4088 | */ |
| 4089 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 4090 | static void stl_sc26198startrxtx(struct stlport *portp, int rx, int tx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4091 | { |
| 4092 | unsigned char imr; |
| 4093 | unsigned long flags; |
| 4094 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 4095 | pr_debug("stl_sc26198startrxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4096 | |
| 4097 | imr = portp->imr; |
| 4098 | if (tx == 0) |
| 4099 | imr &= ~IR_TXRDY; |
| 4100 | else if (tx == 1) |
| 4101 | imr |= IR_TXRDY; |
| 4102 | if (rx == 0) |
| 4103 | imr &= ~(IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG); |
| 4104 | else if (rx > 0) |
| 4105 | imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG; |
| 4106 | |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 4107 | spin_lock_irqsave(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4108 | BRDENABLE(portp->brdnr, portp->pagenr); |
| 4109 | stl_sc26198setreg(portp, IMR, imr); |
| 4110 | BRDDISABLE(portp->brdnr); |
| 4111 | portp->imr = imr; |
| 4112 | if (tx > 0) |
| 4113 | set_bit(ASYI_TXBUSY, &portp->istate); |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 4114 | spin_unlock_irqrestore(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4115 | } |
| 4116 | |
| 4117 | /*****************************************************************************/ |
| 4118 | |
| 4119 | /* |
| 4120 | * Disable all interrupts from this port. |
| 4121 | */ |
| 4122 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 4123 | static void stl_sc26198disableintrs(struct stlport *portp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4124 | { |
| 4125 | unsigned long flags; |
| 4126 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 4127 | pr_debug("stl_sc26198disableintrs(portp=%p)\n", portp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4128 | |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 4129 | spin_lock_irqsave(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4130 | BRDENABLE(portp->brdnr, portp->pagenr); |
| 4131 | portp->imr = 0; |
| 4132 | stl_sc26198setreg(portp, IMR, 0); |
| 4133 | BRDDISABLE(portp->brdnr); |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 4134 | spin_unlock_irqrestore(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4135 | } |
| 4136 | |
| 4137 | /*****************************************************************************/ |
| 4138 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 4139 | static void stl_sc26198sendbreak(struct stlport *portp, int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4140 | { |
| 4141 | unsigned long flags; |
| 4142 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 4143 | pr_debug("stl_sc26198sendbreak(portp=%p,len=%d)\n", portp, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4144 | |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 4145 | spin_lock_irqsave(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4146 | BRDENABLE(portp->brdnr, portp->pagenr); |
| 4147 | if (len == 1) { |
| 4148 | stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK); |
| 4149 | portp->stats.txbreaks++; |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 4150 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4151 | stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK); |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 4152 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4153 | BRDDISABLE(portp->brdnr); |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 4154 | spin_unlock_irqrestore(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4155 | } |
| 4156 | |
| 4157 | /*****************************************************************************/ |
| 4158 | |
| 4159 | /* |
| 4160 | * Take flow control actions... |
| 4161 | */ |
| 4162 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 4163 | static void stl_sc26198flowctrl(struct stlport *portp, int state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4164 | { |
| 4165 | struct tty_struct *tty; |
| 4166 | unsigned long flags; |
| 4167 | unsigned char mr0; |
| 4168 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 4169 | pr_debug("stl_sc26198flowctrl(portp=%p,state=%x)\n", portp, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4170 | |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 4171 | if (portp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4172 | return; |
Alan Cox | d18a750 | 2008-10-13 10:40:07 +0100 | [diff] [blame] | 4173 | tty = tty_port_tty_get(&portp->port); |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 4174 | if (tty == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4175 | return; |
| 4176 | |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 4177 | spin_lock_irqsave(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4178 | BRDENABLE(portp->brdnr, portp->pagenr); |
| 4179 | |
| 4180 | if (state) { |
| 4181 | if (tty->termios->c_iflag & IXOFF) { |
| 4182 | mr0 = stl_sc26198getreg(portp, MR0); |
| 4183 | stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX)); |
| 4184 | stl_sc26198setreg(portp, SCCR, CR_TXSENDXON); |
| 4185 | mr0 |= MR0_SWFRX; |
| 4186 | portp->stats.rxxon++; |
| 4187 | stl_sc26198wait(portp); |
| 4188 | stl_sc26198setreg(portp, MR0, mr0); |
| 4189 | } |
| 4190 | /* |
| 4191 | * Question: should we return RTS to what it was before? It may |
| 4192 | * have been set by an ioctl... Suppose not, since if you have |
| 4193 | * hardware flow control set then it is pretty silly to go and |
| 4194 | * set the RTS line by hand. |
| 4195 | */ |
| 4196 | if (tty->termios->c_cflag & CRTSCTS) { |
| 4197 | stl_sc26198setreg(portp, MR1, |
| 4198 | (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS)); |
| 4199 | stl_sc26198setreg(portp, IOPIOR, |
| 4200 | (stl_sc26198getreg(portp, IOPIOR) | IOPR_RTS)); |
| 4201 | portp->stats.rxrtson++; |
| 4202 | } |
| 4203 | } else { |
| 4204 | if (tty->termios->c_iflag & IXOFF) { |
| 4205 | mr0 = stl_sc26198getreg(portp, MR0); |
| 4206 | stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX)); |
| 4207 | stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF); |
| 4208 | mr0 &= ~MR0_SWFRX; |
| 4209 | portp->stats.rxxoff++; |
| 4210 | stl_sc26198wait(portp); |
| 4211 | stl_sc26198setreg(portp, MR0, mr0); |
| 4212 | } |
| 4213 | if (tty->termios->c_cflag & CRTSCTS) { |
| 4214 | stl_sc26198setreg(portp, MR1, |
| 4215 | (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS)); |
| 4216 | stl_sc26198setreg(portp, IOPIOR, |
| 4217 | (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS)); |
| 4218 | portp->stats.rxrtsoff++; |
| 4219 | } |
| 4220 | } |
| 4221 | |
| 4222 | BRDDISABLE(portp->brdnr); |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 4223 | spin_unlock_irqrestore(&brd_lock, flags); |
Alan Cox | d18a750 | 2008-10-13 10:40:07 +0100 | [diff] [blame] | 4224 | tty_kref_put(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4225 | } |
| 4226 | |
| 4227 | /*****************************************************************************/ |
| 4228 | |
| 4229 | /* |
| 4230 | * Send a flow control character. |
| 4231 | */ |
| 4232 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 4233 | static void stl_sc26198sendflow(struct stlport *portp, int state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4234 | { |
| 4235 | struct tty_struct *tty; |
| 4236 | unsigned long flags; |
| 4237 | unsigned char mr0; |
| 4238 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 4239 | pr_debug("stl_sc26198sendflow(portp=%p,state=%x)\n", portp, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4240 | |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 4241 | if (portp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4242 | return; |
Alan Cox | d18a750 | 2008-10-13 10:40:07 +0100 | [diff] [blame] | 4243 | tty = tty_port_tty_get(&portp->port); |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 4244 | if (tty == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4245 | return; |
| 4246 | |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 4247 | spin_lock_irqsave(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4248 | BRDENABLE(portp->brdnr, portp->pagenr); |
| 4249 | if (state) { |
| 4250 | mr0 = stl_sc26198getreg(portp, MR0); |
| 4251 | stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX)); |
| 4252 | stl_sc26198setreg(portp, SCCR, CR_TXSENDXON); |
| 4253 | mr0 |= MR0_SWFRX; |
| 4254 | portp->stats.rxxon++; |
| 4255 | stl_sc26198wait(portp); |
| 4256 | stl_sc26198setreg(portp, MR0, mr0); |
| 4257 | } else { |
| 4258 | mr0 = stl_sc26198getreg(portp, MR0); |
| 4259 | stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX)); |
| 4260 | stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF); |
| 4261 | mr0 &= ~MR0_SWFRX; |
| 4262 | portp->stats.rxxoff++; |
| 4263 | stl_sc26198wait(portp); |
| 4264 | stl_sc26198setreg(portp, MR0, mr0); |
| 4265 | } |
| 4266 | BRDDISABLE(portp->brdnr); |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 4267 | spin_unlock_irqrestore(&brd_lock, flags); |
Alan Cox | d18a750 | 2008-10-13 10:40:07 +0100 | [diff] [blame] | 4268 | tty_kref_put(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4269 | } |
| 4270 | |
| 4271 | /*****************************************************************************/ |
| 4272 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 4273 | static void stl_sc26198flush(struct stlport *portp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4274 | { |
| 4275 | unsigned long flags; |
| 4276 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 4277 | pr_debug("stl_sc26198flush(portp=%p)\n", portp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4278 | |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 4279 | if (portp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4280 | return; |
| 4281 | |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 4282 | spin_lock_irqsave(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4283 | BRDENABLE(portp->brdnr, portp->pagenr); |
| 4284 | stl_sc26198setreg(portp, SCCR, CR_TXRESET); |
| 4285 | stl_sc26198setreg(portp, SCCR, portp->crenable); |
| 4286 | BRDDISABLE(portp->brdnr); |
| 4287 | portp->tx.tail = portp->tx.head; |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 4288 | spin_unlock_irqrestore(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4289 | } |
| 4290 | |
| 4291 | /*****************************************************************************/ |
| 4292 | |
| 4293 | /* |
| 4294 | * Return the current state of data flow on this port. This is only |
| 4295 | * really interresting when determining if data has fully completed |
| 4296 | * transmission or not... The sc26198 interrupt scheme cannot |
| 4297 | * determine when all data has actually drained, so we need to |
| 4298 | * check the port statusy register to be sure. |
| 4299 | */ |
| 4300 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 4301 | static int stl_sc26198datastate(struct stlport *portp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4302 | { |
| 4303 | unsigned long flags; |
| 4304 | unsigned char sr; |
| 4305 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 4306 | pr_debug("stl_sc26198datastate(portp=%p)\n", portp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4307 | |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 4308 | if (portp == NULL) |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 4309 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4310 | if (test_bit(ASYI_TXBUSY, &portp->istate)) |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 4311 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4312 | |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 4313 | spin_lock_irqsave(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4314 | BRDENABLE(portp->brdnr, portp->pagenr); |
| 4315 | sr = stl_sc26198getreg(portp, SR); |
| 4316 | BRDDISABLE(portp->brdnr); |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 4317 | spin_unlock_irqrestore(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4318 | |
Jesper Juhl | 014c254 | 2006-01-15 02:37:08 +0100 | [diff] [blame] | 4319 | return (sr & SR_TXEMPTY) ? 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4320 | } |
| 4321 | |
| 4322 | /*****************************************************************************/ |
| 4323 | |
| 4324 | /* |
| 4325 | * Delay for a small amount of time, to give the sc26198 a chance |
| 4326 | * to process a command... |
| 4327 | */ |
| 4328 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 4329 | static void stl_sc26198wait(struct stlport *portp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4330 | { |
| 4331 | int i; |
| 4332 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 4333 | pr_debug("stl_sc26198wait(portp=%p)\n", portp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4334 | |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 4335 | if (portp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4336 | return; |
| 4337 | |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 4338 | for (i = 0; i < 20; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4339 | stl_sc26198getglobreg(portp, TSTR); |
| 4340 | } |
| 4341 | |
| 4342 | /*****************************************************************************/ |
| 4343 | |
| 4344 | /* |
| 4345 | * If we are TX flow controlled and in IXANY mode then we may |
| 4346 | * need to unflow control here. We gotta do this because of the |
| 4347 | * automatic flow control modes of the sc26198. |
| 4348 | */ |
| 4349 | |
Jiri Slaby | 60be481 | 2006-12-08 02:38:40 -0800 | [diff] [blame] | 4350 | static void stl_sc26198txunflow(struct stlport *portp, struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4351 | { |
| 4352 | unsigned char mr0; |
| 4353 | |
| 4354 | mr0 = stl_sc26198getreg(portp, MR0); |
| 4355 | stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX)); |
| 4356 | stl_sc26198setreg(portp, SCCR, CR_HOSTXON); |
| 4357 | stl_sc26198wait(portp); |
| 4358 | stl_sc26198setreg(portp, MR0, mr0); |
| 4359 | clear_bit(ASYI_TXFLOWED, &portp->istate); |
| 4360 | } |
| 4361 | |
| 4362 | /*****************************************************************************/ |
| 4363 | |
| 4364 | /* |
| 4365 | * Interrupt service routine for sc26198 panels. |
| 4366 | */ |
| 4367 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 4368 | static void stl_sc26198intr(struct stlpanel *panelp, unsigned int iobase) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4369 | { |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 4370 | struct stlport *portp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4371 | unsigned int iack; |
| 4372 | |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 4373 | spin_lock(&brd_lock); |
| 4374 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4375 | /* |
| 4376 | * Work around bug in sc26198 chip... Cannot have A6 address |
| 4377 | * line of UART high, else iack will be returned as 0. |
| 4378 | */ |
| 4379 | outb(0, (iobase + 1)); |
| 4380 | |
| 4381 | iack = inb(iobase + XP_IACK); |
| 4382 | portp = panelp->ports[(iack & IVR_CHANMASK) + ((iobase & 0x4) << 1)]; |
| 4383 | |
| 4384 | if (iack & IVR_RXDATA) |
| 4385 | stl_sc26198rxisr(portp, iack); |
| 4386 | else if (iack & IVR_TXDATA) |
| 4387 | stl_sc26198txisr(portp); |
| 4388 | else |
| 4389 | stl_sc26198otherisr(portp, iack); |
Alan Cox | b65b5b5 | 2006-06-27 02:54:05 -0700 | [diff] [blame] | 4390 | |
| 4391 | spin_unlock(&brd_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4392 | } |
| 4393 | |
| 4394 | /*****************************************************************************/ |
| 4395 | |
| 4396 | /* |
| 4397 | * Transmit interrupt handler. This has gotta be fast! Handling TX |
| 4398 | * chars is pretty simple, stuff as many as possible from the TX buffer |
| 4399 | * into the sc26198 FIFO. |
| 4400 | * In practice it is possible that interrupts are enabled but that the |
| 4401 | * port has been hung up. Need to handle not having any TX buffer here, |
| 4402 | * this is done by using the side effect that head and tail will also |
| 4403 | * be NULL if the buffer has been freed. |
| 4404 | */ |
| 4405 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 4406 | static void stl_sc26198txisr(struct stlport *portp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4407 | { |
Alan Cox | d18a750 | 2008-10-13 10:40:07 +0100 | [diff] [blame] | 4408 | struct tty_struct *tty; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4409 | unsigned int ioaddr; |
| 4410 | unsigned char mr0; |
| 4411 | int len, stlen; |
| 4412 | char *head, *tail; |
| 4413 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 4414 | pr_debug("stl_sc26198txisr(portp=%p)\n", portp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4415 | |
| 4416 | ioaddr = portp->ioaddr; |
| 4417 | head = portp->tx.head; |
| 4418 | tail = portp->tx.tail; |
| 4419 | len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head)); |
| 4420 | if ((len == 0) || ((len < STL_TXBUFLOW) && |
| 4421 | (test_bit(ASYI_TXLOW, &portp->istate) == 0))) { |
| 4422 | set_bit(ASYI_TXLOW, &portp->istate); |
Alan Cox | d18a750 | 2008-10-13 10:40:07 +0100 | [diff] [blame] | 4423 | tty = tty_port_tty_get(&portp->port); |
| 4424 | if (tty) { |
| 4425 | tty_wakeup(tty); |
| 4426 | tty_kref_put(tty); |
| 4427 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4428 | } |
| 4429 | |
| 4430 | if (len == 0) { |
| 4431 | outb((MR0 | portp->uartaddr), (ioaddr + XP_ADDR)); |
| 4432 | mr0 = inb(ioaddr + XP_DATA); |
| 4433 | if ((mr0 & MR0_TXMASK) == MR0_TXEMPTY) { |
| 4434 | portp->imr &= ~IR_TXRDY; |
| 4435 | outb((IMR | portp->uartaddr), (ioaddr + XP_ADDR)); |
| 4436 | outb(portp->imr, (ioaddr + XP_DATA)); |
| 4437 | clear_bit(ASYI_TXBUSY, &portp->istate); |
| 4438 | } else { |
| 4439 | mr0 |= ((mr0 & ~MR0_TXMASK) | MR0_TXEMPTY); |
| 4440 | outb(mr0, (ioaddr + XP_DATA)); |
| 4441 | } |
| 4442 | } else { |
Jiri Slaby | 843b568 | 2006-12-08 02:39:12 -0800 | [diff] [blame] | 4443 | len = min(len, SC26198_TXFIFOSIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4444 | portp->stats.txtotal += len; |
Jiri Slaby | 319fe7c | 2008-02-07 00:16:36 -0800 | [diff] [blame] | 4445 | stlen = min_t(unsigned int, len, |
| 4446 | (portp->tx.buf + STL_TXBUFSIZE) - tail); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4447 | outb(GTXFIFO, (ioaddr + XP_ADDR)); |
| 4448 | outsb((ioaddr + XP_DATA), tail, stlen); |
| 4449 | len -= stlen; |
| 4450 | tail += stlen; |
| 4451 | if (tail >= (portp->tx.buf + STL_TXBUFSIZE)) |
| 4452 | tail = portp->tx.buf; |
| 4453 | if (len > 0) { |
| 4454 | outsb((ioaddr + XP_DATA), tail, len); |
| 4455 | tail += len; |
| 4456 | } |
| 4457 | portp->tx.tail = tail; |
| 4458 | } |
| 4459 | } |
| 4460 | |
| 4461 | /*****************************************************************************/ |
| 4462 | |
| 4463 | /* |
| 4464 | * Receive character interrupt handler. Determine if we have good chars |
| 4465 | * or bad chars and then process appropriately. Good chars are easy |
| 4466 | * just shove the lot into the RX buffer and set all status byte to 0. |
| 4467 | * If a bad RX char then process as required. This routine needs to be |
| 4468 | * fast! In practice it is possible that we get an interrupt on a port |
| 4469 | * that is closed. This can happen on hangups - since they completely |
| 4470 | * shutdown a port not in user context. Need to handle this case. |
| 4471 | */ |
| 4472 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 4473 | static void stl_sc26198rxisr(struct stlport *portp, unsigned int iack) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4474 | { |
| 4475 | struct tty_struct *tty; |
| 4476 | unsigned int len, buflen, ioaddr; |
| 4477 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 4478 | pr_debug("stl_sc26198rxisr(portp=%p,iack=%x)\n", portp, iack); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4479 | |
Alan Cox | d18a750 | 2008-10-13 10:40:07 +0100 | [diff] [blame] | 4480 | tty = tty_port_tty_get(&portp->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4481 | ioaddr = portp->ioaddr; |
| 4482 | outb(GIBCR, (ioaddr + XP_ADDR)); |
| 4483 | len = inb(ioaddr + XP_DATA) + 1; |
| 4484 | |
| 4485 | if ((iack & IVR_TYPEMASK) == IVR_RXDATA) { |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 4486 | if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) { |
Jiri Slaby | 319fe7c | 2008-02-07 00:16:36 -0800 | [diff] [blame] | 4487 | len = min_t(unsigned int, len, sizeof(stl_unwanted)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4488 | outb(GRXFIFO, (ioaddr + XP_ADDR)); |
| 4489 | insb((ioaddr + XP_DATA), &stl_unwanted[0], len); |
| 4490 | portp->stats.rxlost += len; |
| 4491 | portp->stats.rxtotal += len; |
| 4492 | } else { |
Jiri Slaby | 843b568 | 2006-12-08 02:39:12 -0800 | [diff] [blame] | 4493 | len = min(len, buflen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4494 | if (len > 0) { |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 4495 | unsigned char *ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4496 | outb(GRXFIFO, (ioaddr + XP_ADDR)); |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 4497 | tty_prepare_flip_string(tty, &ptr, len); |
| 4498 | insb((ioaddr + XP_DATA), ptr, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4499 | tty_schedule_flip(tty); |
| 4500 | portp->stats.rxtotal += len; |
| 4501 | } |
| 4502 | } |
| 4503 | } else { |
| 4504 | stl_sc26198rxbadchars(portp); |
| 4505 | } |
| 4506 | |
| 4507 | /* |
| 4508 | * If we are TX flow controlled and in IXANY mode then we may need |
| 4509 | * to unflow control here. We gotta do this because of the automatic |
| 4510 | * flow control modes of the sc26198. |
| 4511 | */ |
| 4512 | if (test_bit(ASYI_TXFLOWED, &portp->istate)) { |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 4513 | if ((tty != NULL) && |
| 4514 | (tty->termios != NULL) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4515 | (tty->termios->c_iflag & IXANY)) { |
| 4516 | stl_sc26198txunflow(portp, tty); |
| 4517 | } |
| 4518 | } |
Alan Cox | d18a750 | 2008-10-13 10:40:07 +0100 | [diff] [blame] | 4519 | tty_kref_put(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4520 | } |
| 4521 | |
| 4522 | /*****************************************************************************/ |
| 4523 | |
| 4524 | /* |
| 4525 | * Process an RX bad character. |
| 4526 | */ |
| 4527 | |
Jiri Slaby | 60be481 | 2006-12-08 02:38:40 -0800 | [diff] [blame] | 4528 | static void stl_sc26198rxbadch(struct stlport *portp, unsigned char status, char ch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4529 | { |
| 4530 | struct tty_struct *tty; |
| 4531 | unsigned int ioaddr; |
| 4532 | |
Alan Cox | d18a750 | 2008-10-13 10:40:07 +0100 | [diff] [blame] | 4533 | tty = tty_port_tty_get(&portp->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4534 | ioaddr = portp->ioaddr; |
| 4535 | |
| 4536 | if (status & SR_RXPARITY) |
| 4537 | portp->stats.rxparity++; |
| 4538 | if (status & SR_RXFRAMING) |
| 4539 | portp->stats.rxframing++; |
| 4540 | if (status & SR_RXOVERRUN) |
| 4541 | portp->stats.rxoverrun++; |
| 4542 | if (status & SR_RXBREAK) |
| 4543 | portp->stats.rxbreaks++; |
| 4544 | |
Jiri Slaby | 615e4a7 | 2006-12-08 02:38:38 -0800 | [diff] [blame] | 4545 | if ((tty != NULL) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4546 | ((portp->rxignoremsk & status) == 0)) { |
| 4547 | if (portp->rxmarkmsk & status) { |
| 4548 | if (status & SR_RXBREAK) { |
| 4549 | status = TTY_BREAK; |
Alan Cox | f8ae476 | 2008-07-16 21:56:37 +0100 | [diff] [blame] | 4550 | if (portp->port.flags & ASYNC_SAK) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4551 | do_SAK(tty); |
| 4552 | BRDENABLE(portp->brdnr, portp->pagenr); |
| 4553 | } |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 4554 | } else if (status & SR_RXPARITY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4555 | status = TTY_PARITY; |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 4556 | else if (status & SR_RXFRAMING) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4557 | status = TTY_FRAME; |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 4558 | else if(status & SR_RXOVERRUN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4559 | status = TTY_OVERRUN; |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 4560 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4561 | status = 0; |
Jiri Slaby | c62429d | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 4562 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4563 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4564 | |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 4565 | tty_insert_flip_char(tty, ch, status); |
| 4566 | tty_schedule_flip(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4567 | |
| 4568 | if (status == 0) |
| 4569 | portp->stats.rxtotal++; |
| 4570 | } |
Alan Cox | d18a750 | 2008-10-13 10:40:07 +0100 | [diff] [blame] | 4571 | tty_kref_put(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4572 | } |
| 4573 | |
| 4574 | /*****************************************************************************/ |
| 4575 | |
| 4576 | /* |
| 4577 | * Process all characters in the RX FIFO of the UART. Check all char |
| 4578 | * status bytes as well, and process as required. We need to check |
| 4579 | * all bytes in the FIFO, in case some more enter the FIFO while we |
| 4580 | * are here. To get the exact character error type we need to switch |
| 4581 | * into CHAR error mode (that is why we need to make sure we empty |
| 4582 | * the FIFO). |
| 4583 | */ |
| 4584 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 4585 | static void stl_sc26198rxbadchars(struct stlport *portp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4586 | { |
| 4587 | unsigned char status, mr1; |
| 4588 | char ch; |
| 4589 | |
| 4590 | /* |
| 4591 | * To get the precise error type for each character we must switch |
| 4592 | * back into CHAR error mode. |
| 4593 | */ |
| 4594 | mr1 = stl_sc26198getreg(portp, MR1); |
| 4595 | stl_sc26198setreg(portp, MR1, (mr1 & ~MR1_ERRBLOCK)); |
| 4596 | |
| 4597 | while ((status = stl_sc26198getreg(portp, SR)) & SR_RXRDY) { |
| 4598 | stl_sc26198setreg(portp, SCCR, CR_CLEARRXERR); |
| 4599 | ch = stl_sc26198getreg(portp, RXFIFO); |
| 4600 | stl_sc26198rxbadch(portp, status, ch); |
| 4601 | } |
| 4602 | |
| 4603 | /* |
| 4604 | * To get correct interrupt class we must switch back into BLOCK |
| 4605 | * error mode. |
| 4606 | */ |
| 4607 | stl_sc26198setreg(portp, MR1, mr1); |
| 4608 | } |
| 4609 | |
| 4610 | /*****************************************************************************/ |
| 4611 | |
| 4612 | /* |
| 4613 | * Other interrupt handler. This includes modem signals, flow |
| 4614 | * control actions, etc. Most stuff is left to off-level interrupt |
| 4615 | * processing time. |
| 4616 | */ |
| 4617 | |
Jiri Slaby | ca7ed0f | 2006-12-08 02:38:39 -0800 | [diff] [blame] | 4618 | static void stl_sc26198otherisr(struct stlport *portp, unsigned int iack) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4619 | { |
| 4620 | unsigned char cir, ipr, xisr; |
| 4621 | |
Jiri Slaby | a0564e1 | 2006-12-08 02:38:37 -0800 | [diff] [blame] | 4622 | pr_debug("stl_sc26198otherisr(portp=%p,iack=%x)\n", portp, iack); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4623 | |
| 4624 | cir = stl_sc26198getglobreg(portp, CIR); |
| 4625 | |
| 4626 | switch (cir & CIR_SUBTYPEMASK) { |
| 4627 | case CIR_SUBCOS: |
| 4628 | ipr = stl_sc26198getreg(portp, IPR); |
| 4629 | if (ipr & IPR_DCDCHANGE) { |
Jiri Slaby | ccfea3c | 2008-02-07 00:16:39 -0800 | [diff] [blame] | 4630 | stl_cd_change(portp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4631 | portp->stats.modem++; |
| 4632 | } |
| 4633 | break; |
| 4634 | case CIR_SUBXONXOFF: |
| 4635 | xisr = stl_sc26198getreg(portp, XISR); |
| 4636 | if (xisr & XISR_RXXONGOT) { |
| 4637 | set_bit(ASYI_TXFLOWED, &portp->istate); |
| 4638 | portp->stats.txxoff++; |
| 4639 | } |
| 4640 | if (xisr & XISR_RXXOFFGOT) { |
| 4641 | clear_bit(ASYI_TXFLOWED, &portp->istate); |
| 4642 | portp->stats.txxon++; |
| 4643 | } |
| 4644 | break; |
| 4645 | case CIR_SUBBREAK: |
| 4646 | stl_sc26198setreg(portp, SCCR, CR_BREAKRESET); |
| 4647 | stl_sc26198rxbadchars(portp); |
| 4648 | break; |
| 4649 | default: |
| 4650 | break; |
| 4651 | } |
| 4652 | } |
| 4653 | |
Jiri Slaby | fc06b5c | 2006-12-08 02:39:13 -0800 | [diff] [blame] | 4654 | static void stl_free_isabrds(void) |
| 4655 | { |
| 4656 | struct stlbrd *brdp; |
| 4657 | unsigned int i; |
| 4658 | |
| 4659 | for (i = 0; i < stl_nrbrds; i++) { |
| 4660 | if ((brdp = stl_brds[i]) == NULL || (brdp->state & STL_PROBED)) |
| 4661 | continue; |
| 4662 | |
| 4663 | free_irq(brdp->irq, brdp); |
| 4664 | |
| 4665 | stl_cleanup_panels(brdp); |
| 4666 | |
| 4667 | release_region(brdp->ioaddr1, brdp->iosize1); |
| 4668 | if (brdp->iosize2 > 0) |
| 4669 | release_region(brdp->ioaddr2, brdp->iosize2); |
| 4670 | |
| 4671 | kfree(brdp); |
| 4672 | stl_brds[i] = NULL; |
| 4673 | } |
| 4674 | } |
| 4675 | |
Jiri Slaby | 23b85a1 | 2006-12-08 02:38:40 -0800 | [diff] [blame] | 4676 | /* |
| 4677 | * Loadable module initialization stuff. |
| 4678 | */ |
| 4679 | static int __init stallion_module_init(void) |
| 4680 | { |
Jiri Slaby | 843b568 | 2006-12-08 02:39:12 -0800 | [diff] [blame] | 4681 | struct stlbrd *brdp; |
| 4682 | struct stlconf conf; |
Jiri Slaby | aeaccfe | 2006-12-08 02:39:16 -0800 | [diff] [blame] | 4683 | unsigned int i, j; |
Jiri Slaby | fc06b5c | 2006-12-08 02:39:13 -0800 | [diff] [blame] | 4684 | int retval; |
Jiri Slaby | 23b85a1 | 2006-12-08 02:38:40 -0800 | [diff] [blame] | 4685 | |
| 4686 | printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion); |
| 4687 | |
| 4688 | spin_lock_init(&stallion_lock); |
| 4689 | spin_lock_init(&brd_lock); |
| 4690 | |
Jiri Slaby | e415109 | 2007-06-08 13:46:52 -0700 | [diff] [blame] | 4691 | stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS); |
| 4692 | if (!stl_serial) { |
| 4693 | retval = -ENOMEM; |
| 4694 | goto err; |
| 4695 | } |
| 4696 | |
| 4697 | stl_serial->owner = THIS_MODULE; |
| 4698 | stl_serial->driver_name = stl_drvname; |
| 4699 | stl_serial->name = "ttyE"; |
| 4700 | stl_serial->major = STL_SERIALMAJOR; |
| 4701 | stl_serial->minor_start = 0; |
| 4702 | stl_serial->type = TTY_DRIVER_TYPE_SERIAL; |
| 4703 | stl_serial->subtype = SERIAL_TYPE_NORMAL; |
| 4704 | stl_serial->init_termios = stl_deftermios; |
| 4705 | stl_serial->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; |
| 4706 | tty_set_operations(stl_serial, &stl_ops); |
| 4707 | |
| 4708 | retval = tty_register_driver(stl_serial); |
| 4709 | if (retval) { |
| 4710 | printk("STALLION: failed to register serial driver\n"); |
| 4711 | goto err_frtty; |
| 4712 | } |
| 4713 | |
Jiri Slaby | 843b568 | 2006-12-08 02:39:12 -0800 | [diff] [blame] | 4714 | /* |
| 4715 | * Find any dynamically supported boards. That is via module load |
| 4716 | * line options. |
| 4717 | */ |
| 4718 | for (i = stl_nrbrds; i < stl_nargs; i++) { |
| 4719 | memset(&conf, 0, sizeof(conf)); |
| 4720 | if (stl_parsebrd(&conf, stl_brdsp[i]) == 0) |
| 4721 | continue; |
| 4722 | if ((brdp = stl_allocbrd()) == NULL) |
| 4723 | continue; |
| 4724 | brdp->brdnr = i; |
| 4725 | brdp->brdtype = conf.brdtype; |
| 4726 | brdp->ioaddr1 = conf.ioaddr1; |
| 4727 | brdp->ioaddr2 = conf.ioaddr2; |
| 4728 | brdp->irq = conf.irq; |
| 4729 | brdp->irqtype = conf.irqtype; |
Ingo Korb | b08b5ad | 2007-06-23 17:16:35 -0700 | [diff] [blame] | 4730 | stl_brds[brdp->brdnr] = brdp; |
| 4731 | if (stl_brdinit(brdp)) { |
| 4732 | stl_brds[brdp->brdnr] = NULL; |
Jiri Slaby | 843b568 | 2006-12-08 02:39:12 -0800 | [diff] [blame] | 4733 | kfree(brdp); |
Ingo Korb | b08b5ad | 2007-06-23 17:16:35 -0700 | [diff] [blame] | 4734 | } else { |
Jiri Slaby | aeaccfe | 2006-12-08 02:39:16 -0800 | [diff] [blame] | 4735 | for (j = 0; j < brdp->nrports; j++) |
| 4736 | tty_register_device(stl_serial, |
| 4737 | brdp->brdnr * STL_MAXPORTS + j, NULL); |
Jiri Slaby | 843b568 | 2006-12-08 02:39:12 -0800 | [diff] [blame] | 4738 | stl_nrbrds = i + 1; |
Jiri Slaby | 79cfe7a | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 4739 | } |
Jiri Slaby | 843b568 | 2006-12-08 02:39:12 -0800 | [diff] [blame] | 4740 | } |
Jiri Slaby | 23b85a1 | 2006-12-08 02:38:40 -0800 | [diff] [blame] | 4741 | |
Jiri Slaby | 79cfe7a | 2006-12-08 02:39:14 -0800 | [diff] [blame] | 4742 | /* this has to be _after_ isa finding because of locking */ |
Jiri Slaby | b1b84fe | 2006-12-08 02:39:09 -0800 | [diff] [blame] | 4743 | retval = pci_register_driver(&stl_pcidriver); |
Jiri Slaby | e415109 | 2007-06-08 13:46:52 -0700 | [diff] [blame] | 4744 | if (retval && stl_nrbrds == 0) { |
| 4745 | printk(KERN_ERR "STALLION: can't register pci driver\n"); |
| 4746 | goto err_unrtty; |
Jiri Slaby | fc06b5c | 2006-12-08 02:39:13 -0800 | [diff] [blame] | 4747 | } |
Jiri Slaby | 23b85a1 | 2006-12-08 02:38:40 -0800 | [diff] [blame] | 4748 | |
| 4749 | /* |
| 4750 | * Set up a character driver for per board stuff. This is mainly used |
| 4751 | * to do stats ioctls on the ports. |
| 4752 | */ |
| 4753 | if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stl_fsiomem)) |
| 4754 | printk("STALLION: failed to register serial board device\n"); |
| 4755 | |
| 4756 | stallion_class = class_create(THIS_MODULE, "staliomem"); |
Jiri Slaby | e415109 | 2007-06-08 13:46:52 -0700 | [diff] [blame] | 4757 | if (IS_ERR(stallion_class)) |
| 4758 | printk("STALLION: failed to create class\n"); |
Jiri Slaby | 23b85a1 | 2006-12-08 02:38:40 -0800 | [diff] [blame] | 4759 | for (i = 0; i < 4; i++) |
Greg Kroah-Hartman | 03457cd | 2008-07-21 20:03:34 -0700 | [diff] [blame] | 4760 | device_create(stallion_class, NULL, MKDEV(STL_SIOMEMMAJOR, i), |
| 4761 | NULL, "staliomem%d", i); |
Jiri Slaby | 23b85a1 | 2006-12-08 02:38:40 -0800 | [diff] [blame] | 4762 | |
Jiri Slaby | 23b85a1 | 2006-12-08 02:38:40 -0800 | [diff] [blame] | 4763 | return 0; |
Jiri Slaby | e415109 | 2007-06-08 13:46:52 -0700 | [diff] [blame] | 4764 | err_unrtty: |
| 4765 | tty_unregister_driver(stl_serial); |
| 4766 | err_frtty: |
Jiri Slaby | fc06b5c | 2006-12-08 02:39:13 -0800 | [diff] [blame] | 4767 | put_tty_driver(stl_serial); |
Jiri Slaby | b1b84fe | 2006-12-08 02:39:09 -0800 | [diff] [blame] | 4768 | err: |
| 4769 | return retval; |
Jiri Slaby | 23b85a1 | 2006-12-08 02:38:40 -0800 | [diff] [blame] | 4770 | } |
| 4771 | |
| 4772 | static void __exit stallion_module_exit(void) |
| 4773 | { |
Jiri Slaby | aeaccfe | 2006-12-08 02:39:16 -0800 | [diff] [blame] | 4774 | struct stlbrd *brdp; |
| 4775 | unsigned int i, j; |
Jiri Slaby | 23b85a1 | 2006-12-08 02:38:40 -0800 | [diff] [blame] | 4776 | |
| 4777 | pr_debug("cleanup_module()\n"); |
| 4778 | |
| 4779 | printk(KERN_INFO "Unloading %s: version %s\n", stl_drvtitle, |
| 4780 | stl_drvversion); |
| 4781 | |
| 4782 | /* |
| 4783 | * Free up all allocated resources used by the ports. This includes |
| 4784 | * memory and interrupts. As part of this process we will also do |
| 4785 | * a hangup on every open port - to try to flush out any processes |
| 4786 | * hanging onto ports. |
| 4787 | */ |
Jiri Slaby | aeaccfe | 2006-12-08 02:39:16 -0800 | [diff] [blame] | 4788 | for (i = 0; i < stl_nrbrds; i++) { |
| 4789 | if ((brdp = stl_brds[i]) == NULL || (brdp->state & STL_PROBED)) |
| 4790 | continue; |
| 4791 | for (j = 0; j < brdp->nrports; j++) |
| 4792 | tty_unregister_device(stl_serial, |
| 4793 | brdp->brdnr * STL_MAXPORTS + j); |
| 4794 | } |
Jiri Slaby | fc06b5c | 2006-12-08 02:39:13 -0800 | [diff] [blame] | 4795 | |
Jiri Slaby | 23b85a1 | 2006-12-08 02:38:40 -0800 | [diff] [blame] | 4796 | for (i = 0; i < 4; i++) |
tonyj@suse.de | 07c015e | 2007-08-07 22:28:44 -0700 | [diff] [blame] | 4797 | device_destroy(stallion_class, MKDEV(STL_SIOMEMMAJOR, i)); |
Akinobu Mita | 68fc4fa | 2007-07-19 01:47:50 -0700 | [diff] [blame] | 4798 | unregister_chrdev(STL_SIOMEMMAJOR, "staliomem"); |
Jiri Slaby | 23b85a1 | 2006-12-08 02:38:40 -0800 | [diff] [blame] | 4799 | class_destroy(stallion_class); |
| 4800 | |
Jiri Slaby | b1b84fe | 2006-12-08 02:39:09 -0800 | [diff] [blame] | 4801 | pci_unregister_driver(&stl_pcidriver); |
| 4802 | |
Jiri Slaby | fc06b5c | 2006-12-08 02:39:13 -0800 | [diff] [blame] | 4803 | stl_free_isabrds(); |
Jiri Slaby | e415109 | 2007-06-08 13:46:52 -0700 | [diff] [blame] | 4804 | |
| 4805 | tty_unregister_driver(stl_serial); |
| 4806 | put_tty_driver(stl_serial); |
Jiri Slaby | 23b85a1 | 2006-12-08 02:38:40 -0800 | [diff] [blame] | 4807 | } |
| 4808 | |
| 4809 | module_init(stallion_module_init); |
| 4810 | module_exit(stallion_module_exit); |
| 4811 | |
| 4812 | MODULE_AUTHOR("Greg Ungerer"); |
| 4813 | MODULE_DESCRIPTION("Stallion Multiport Serial Driver"); |
| 4814 | MODULE_LICENSE("GPL"); |