Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /*****************************************************************************/ |
| 2 | |
| 3 | /* |
| 4 | * istallion.c -- stallion intelligent 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 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | */ |
| 18 | |
| 19 | /*****************************************************************************/ |
| 20 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/module.h> |
| 22 | #include <linux/slab.h> |
| 23 | #include <linux/interrupt.h> |
| 24 | #include <linux/tty.h> |
| 25 | #include <linux/tty_flip.h> |
| 26 | #include <linux/serial.h> |
| 27 | #include <linux/cdk.h> |
| 28 | #include <linux/comstats.h> |
| 29 | #include <linux/istallion.h> |
| 30 | #include <linux/ioport.h> |
| 31 | #include <linux/delay.h> |
| 32 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <linux/device.h> |
| 34 | #include <linux/wait.h> |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 35 | #include <linux/eisa.h> |
Jiri Slaby | a3f8d9d | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 36 | #include <linux/ctype.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
| 38 | #include <asm/io.h> |
| 39 | #include <asm/uaccess.h> |
| 40 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #include <linux/pci.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
| 43 | /*****************************************************************************/ |
| 44 | |
| 45 | /* |
| 46 | * Define different board types. Not all of the following board types |
| 47 | * are supported by this driver. But I will use the standard "assigned" |
| 48 | * board numbers. Currently supported boards are abbreviated as: |
| 49 | * ECP = EasyConnection 8/64, ONB = ONboard, BBY = Brumby and |
| 50 | * STAL = Stallion. |
| 51 | */ |
| 52 | #define BRD_UNKNOWN 0 |
| 53 | #define BRD_STALLION 1 |
| 54 | #define BRD_BRUMBY4 2 |
| 55 | #define BRD_ONBOARD2 3 |
| 56 | #define BRD_ONBOARD 4 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | #define BRD_ONBOARDE 7 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | #define BRD_ECP 23 |
| 59 | #define BRD_ECPE 24 |
| 60 | #define BRD_ECPMC 25 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | #define BRD_ECPPCI 29 |
| 62 | |
| 63 | #define BRD_BRUMBY BRD_BRUMBY4 |
| 64 | |
| 65 | /* |
| 66 | * Define a configuration structure to hold the board configuration. |
| 67 | * Need to set this up in the code (for now) with the boards that are |
| 68 | * to be configured into the system. This is what needs to be modified |
| 69 | * when adding/removing/modifying boards. Each line entry in the |
| 70 | * stli_brdconf[] array is a board. Each line contains io/irq/memory |
| 71 | * ranges for that board (as well as what type of board it is). |
| 72 | * Some examples: |
| 73 | * { BRD_ECP, 0x2a0, 0, 0xcc000, 0, 0 }, |
| 74 | * This line will configure an EasyConnection 8/64 at io address 2a0, |
| 75 | * and shared memory address of cc000. Multiple EasyConnection 8/64 |
| 76 | * boards can share the same shared memory address space. No interrupt |
| 77 | * is required for this board type. |
| 78 | * Another example: |
| 79 | * { BRD_ECPE, 0x5000, 0, 0x80000000, 0, 0 }, |
| 80 | * This line will configure an EasyConnection 8/64 EISA in slot 5 and |
| 81 | * shared memory address of 0x80000000 (2 GByte). Multiple |
| 82 | * EasyConnection 8/64 EISA boards can share the same shared memory |
| 83 | * address space. No interrupt is required for this board type. |
| 84 | * Another example: |
| 85 | * { BRD_ONBOARD, 0x240, 0, 0xd0000, 0, 0 }, |
| 86 | * This line will configure an ONboard (ISA type) at io address 240, |
| 87 | * and shared memory address of d0000. Multiple ONboards can share |
| 88 | * the same shared memory address space. No interrupt required. |
| 89 | * Another example: |
| 90 | * { BRD_BRUMBY4, 0x360, 0, 0xc8000, 0, 0 }, |
| 91 | * This line will configure a Brumby board (any number of ports!) at |
| 92 | * io address 360 and shared memory address of c8000. All Brumby boards |
| 93 | * configured into a system must have their own separate io and memory |
| 94 | * addresses. No interrupt is required. |
| 95 | * Another example: |
| 96 | * { BRD_STALLION, 0x330, 0, 0xd0000, 0, 0 }, |
| 97 | * This line will configure an original Stallion board at io address 330 |
| 98 | * and shared memory address d0000 (this would only be valid for a "V4.0" |
| 99 | * or Rev.O Stallion board). All Stallion boards configured into the |
| 100 | * system must have their own separate io and memory addresses. No |
| 101 | * interrupt is required. |
| 102 | */ |
| 103 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 104 | struct stlconf { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | int brdtype; |
| 106 | int ioaddr1; |
| 107 | int ioaddr2; |
| 108 | unsigned long memaddr; |
| 109 | int irq; |
| 110 | int irqtype; |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 111 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
Jiri Slaby | 1328d73 | 2006-12-08 02:39:19 -0800 | [diff] [blame] | 113 | static unsigned int stli_nrbrds; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 115 | /* stli_lock must NOT be taken holding brd_lock */ |
| 116 | static spinlock_t stli_lock; /* TTY logic lock */ |
| 117 | static spinlock_t brd_lock; /* Board logic lock */ |
| 118 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | /* |
| 120 | * There is some experimental EISA board detection code in this driver. |
| 121 | * By default it is disabled, but for those that want to try it out, |
| 122 | * then set the define below to be 1. |
| 123 | */ |
| 124 | #define STLI_EISAPROBE 0 |
| 125 | |
| 126 | /*****************************************************************************/ |
| 127 | |
| 128 | /* |
| 129 | * Define some important driver characteristics. Device major numbers |
| 130 | * allocated as per Linux Device Registry. |
| 131 | */ |
| 132 | #ifndef STL_SIOMEMMAJOR |
| 133 | #define STL_SIOMEMMAJOR 28 |
| 134 | #endif |
| 135 | #ifndef STL_SERIALMAJOR |
| 136 | #define STL_SERIALMAJOR 24 |
| 137 | #endif |
| 138 | #ifndef STL_CALLOUTMAJOR |
| 139 | #define STL_CALLOUTMAJOR 25 |
| 140 | #endif |
| 141 | |
| 142 | /*****************************************************************************/ |
| 143 | |
| 144 | /* |
| 145 | * Define our local driver identity first. Set up stuff to deal with |
| 146 | * all the local structures required by a serial tty driver. |
| 147 | */ |
| 148 | static char *stli_drvtitle = "Stallion Intelligent Multiport Serial Driver"; |
| 149 | static char *stli_drvname = "istallion"; |
| 150 | static char *stli_drvversion = "5.6.0"; |
| 151 | static char *stli_serialname = "ttyE"; |
| 152 | |
| 153 | static struct tty_driver *stli_serial; |
| 154 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
| 156 | #define STLI_TXBUFSIZE 4096 |
| 157 | |
| 158 | /* |
| 159 | * Use a fast local buffer for cooked characters. Typically a whole |
| 160 | * bunch of cooked characters come in for a port, 1 at a time. So we |
| 161 | * save those up into a local buffer, then write out the whole lot |
| 162 | * with a large memcpy. Just use 1 buffer for all ports, since its |
| 163 | * use it is only need for short periods of time by each port. |
| 164 | */ |
| 165 | static char *stli_txcookbuf; |
| 166 | static int stli_txcooksize; |
| 167 | static int stli_txcookrealsize; |
| 168 | static struct tty_struct *stli_txcooktty; |
| 169 | |
| 170 | /* |
| 171 | * Define a local default termios struct. All ports will be created |
| 172 | * with this termios initially. Basically all it defines is a raw port |
| 173 | * at 9600 baud, 8 data bits, no parity, 1 stop bit. |
| 174 | */ |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 175 | static struct ktermios stli_deftermios = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL), |
| 177 | .c_cc = INIT_C_CC, |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 178 | .c_ispeed = 9600, |
| 179 | .c_ospeed = 9600, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | }; |
| 181 | |
| 182 | /* |
| 183 | * Define global stats structures. Not used often, and can be |
| 184 | * re-used for each stats call. |
| 185 | */ |
| 186 | static comstats_t stli_comstats; |
| 187 | static combrd_t stli_brdstats; |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 188 | static struct asystats stli_cdkstats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | |
| 190 | /*****************************************************************************/ |
| 191 | |
Jiri Slaby | b103b5c | 2006-12-08 02:39:21 -0800 | [diff] [blame^] | 192 | static DEFINE_MUTEX(stli_brdslock); |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 193 | static struct stlibrd *stli_brds[STL_MAXBRDS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | |
| 195 | static int stli_shared; |
| 196 | |
| 197 | /* |
| 198 | * Per board state flags. Used with the state field of the board struct. |
| 199 | * Not really much here... All we need to do is keep track of whether |
| 200 | * the board has been detected, and whether it is actually running a slave |
| 201 | * or not. |
| 202 | */ |
| 203 | #define BST_FOUND 0x1 |
| 204 | #define BST_STARTED 0x2 |
| 205 | |
| 206 | /* |
| 207 | * Define the set of port state flags. These are marked for internal |
| 208 | * state purposes only, usually to do with the state of communications |
| 209 | * with the slave. Most of them need to be updated atomically, so always |
| 210 | * use the bit setting operations (unless protected by cli/sti). |
| 211 | */ |
| 212 | #define ST_INITIALIZING 1 |
| 213 | #define ST_OPENING 2 |
| 214 | #define ST_CLOSING 3 |
| 215 | #define ST_CMDING 4 |
| 216 | #define ST_TXBUSY 5 |
| 217 | #define ST_RXING 6 |
| 218 | #define ST_DOFLUSHRX 7 |
| 219 | #define ST_DOFLUSHTX 8 |
| 220 | #define ST_DOSIGS 9 |
| 221 | #define ST_RXSTOP 10 |
| 222 | #define ST_GETSIGS 11 |
| 223 | |
| 224 | /* |
| 225 | * Define an array of board names as printable strings. Handy for |
| 226 | * referencing boards when printing trace and stuff. |
| 227 | */ |
| 228 | static char *stli_brdnames[] = { |
| 229 | "Unknown", |
| 230 | "Stallion", |
| 231 | "Brumby", |
| 232 | "ONboard-MC", |
| 233 | "ONboard", |
| 234 | "Brumby", |
| 235 | "Brumby", |
| 236 | "ONboard-EI", |
Jiri Slaby | a3f8d9d | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 237 | NULL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | "ONboard", |
| 239 | "ONboard-MC", |
| 240 | "ONboard-MC", |
Jiri Slaby | a3f8d9d | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 241 | NULL, |
| 242 | NULL, |
| 243 | NULL, |
| 244 | NULL, |
| 245 | NULL, |
| 246 | NULL, |
| 247 | NULL, |
| 248 | NULL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | "EasyIO", |
| 250 | "EC8/32-AT", |
| 251 | "EC8/32-MC", |
| 252 | "EC8/64-AT", |
| 253 | "EC8/64-EI", |
| 254 | "EC8/64-MC", |
| 255 | "EC8/32-PCI", |
| 256 | "EC8/64-PCI", |
| 257 | "EasyIO-PCI", |
| 258 | "EC/RA-PCI", |
| 259 | }; |
| 260 | |
| 261 | /*****************************************************************************/ |
| 262 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | /* |
| 264 | * Define some string labels for arguments passed from the module |
| 265 | * load line. These allow for easy board definitions, and easy |
| 266 | * modification of the io, memory and irq resoucres. |
| 267 | */ |
| 268 | |
| 269 | static char *board0[8]; |
| 270 | static char *board1[8]; |
| 271 | static char *board2[8]; |
| 272 | static char *board3[8]; |
| 273 | |
| 274 | static char **stli_brdsp[] = { |
| 275 | (char **) &board0, |
| 276 | (char **) &board1, |
| 277 | (char **) &board2, |
| 278 | (char **) &board3 |
| 279 | }; |
| 280 | |
| 281 | /* |
| 282 | * Define a set of common board names, and types. This is used to |
| 283 | * parse any module arguments. |
| 284 | */ |
| 285 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 286 | static struct stlibrdtype { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | char *name; |
| 288 | int type; |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 289 | } stli_brdstr[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | { "stallion", BRD_STALLION }, |
| 291 | { "1", BRD_STALLION }, |
| 292 | { "brumby", BRD_BRUMBY }, |
| 293 | { "brumby4", BRD_BRUMBY }, |
| 294 | { "brumby/4", BRD_BRUMBY }, |
| 295 | { "brumby-4", BRD_BRUMBY }, |
| 296 | { "brumby8", BRD_BRUMBY }, |
| 297 | { "brumby/8", BRD_BRUMBY }, |
| 298 | { "brumby-8", BRD_BRUMBY }, |
| 299 | { "brumby16", BRD_BRUMBY }, |
| 300 | { "brumby/16", BRD_BRUMBY }, |
| 301 | { "brumby-16", BRD_BRUMBY }, |
| 302 | { "2", BRD_BRUMBY }, |
| 303 | { "onboard2", BRD_ONBOARD2 }, |
| 304 | { "onboard-2", BRD_ONBOARD2 }, |
| 305 | { "onboard/2", BRD_ONBOARD2 }, |
| 306 | { "onboard-mc", BRD_ONBOARD2 }, |
| 307 | { "onboard/mc", BRD_ONBOARD2 }, |
| 308 | { "onboard-mca", BRD_ONBOARD2 }, |
| 309 | { "onboard/mca", BRD_ONBOARD2 }, |
| 310 | { "3", BRD_ONBOARD2 }, |
| 311 | { "onboard", BRD_ONBOARD }, |
| 312 | { "onboardat", BRD_ONBOARD }, |
| 313 | { "4", BRD_ONBOARD }, |
| 314 | { "onboarde", BRD_ONBOARDE }, |
| 315 | { "onboard-e", BRD_ONBOARDE }, |
| 316 | { "onboard/e", BRD_ONBOARDE }, |
| 317 | { "onboard-ei", BRD_ONBOARDE }, |
| 318 | { "onboard/ei", BRD_ONBOARDE }, |
| 319 | { "7", BRD_ONBOARDE }, |
| 320 | { "ecp", BRD_ECP }, |
| 321 | { "ecpat", BRD_ECP }, |
| 322 | { "ec8/64", BRD_ECP }, |
| 323 | { "ec8/64-at", BRD_ECP }, |
| 324 | { "ec8/64-isa", BRD_ECP }, |
| 325 | { "23", BRD_ECP }, |
| 326 | { "ecpe", BRD_ECPE }, |
| 327 | { "ecpei", BRD_ECPE }, |
| 328 | { "ec8/64-e", BRD_ECPE }, |
| 329 | { "ec8/64-ei", BRD_ECPE }, |
| 330 | { "24", BRD_ECPE }, |
| 331 | { "ecpmc", BRD_ECPMC }, |
| 332 | { "ec8/64-mc", BRD_ECPMC }, |
| 333 | { "ec8/64-mca", BRD_ECPMC }, |
| 334 | { "25", BRD_ECPMC }, |
| 335 | { "ecppci", BRD_ECPPCI }, |
| 336 | { "ec/ra", BRD_ECPPCI }, |
| 337 | { "ec/ra-pc", BRD_ECPPCI }, |
| 338 | { "ec/ra-pci", BRD_ECPPCI }, |
| 339 | { "29", BRD_ECPPCI }, |
| 340 | }; |
| 341 | |
| 342 | /* |
| 343 | * Define the module agruments. |
| 344 | */ |
| 345 | MODULE_AUTHOR("Greg Ungerer"); |
| 346 | MODULE_DESCRIPTION("Stallion Intelligent Multiport Serial Driver"); |
| 347 | MODULE_LICENSE("GPL"); |
| 348 | |
| 349 | |
Rusty Russell | 8d3b33f | 2006-03-25 03:07:05 -0800 | [diff] [blame] | 350 | module_param_array(board0, charp, NULL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,memaddr]"); |
Rusty Russell | 8d3b33f | 2006-03-25 03:07:05 -0800 | [diff] [blame] | 352 | module_param_array(board1, charp, NULL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,memaddr]"); |
Rusty Russell | 8d3b33f | 2006-03-25 03:07:05 -0800 | [diff] [blame] | 354 | module_param_array(board2, charp, NULL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,memaddr]"); |
Rusty Russell | 8d3b33f | 2006-03-25 03:07:05 -0800 | [diff] [blame] | 356 | module_param_array(board3, charp, NULL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,memaddr]"); |
| 358 | |
Jiri Slaby | a00f33f | 2006-12-08 02:39:20 -0800 | [diff] [blame] | 359 | #if STLI_EISAPROBE != 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | /* |
| 361 | * Set up a default memory address table for EISA board probing. |
| 362 | * The default addresses are all bellow 1Mbyte, which has to be the |
| 363 | * case anyway. They should be safe, since we only read values from |
| 364 | * them, and interrupts are disabled while we do it. If the higher |
| 365 | * memory support is compiled in then we also try probing around |
| 366 | * the 1Gb, 2Gb and 3Gb areas as well... |
| 367 | */ |
| 368 | static unsigned long stli_eisamemprobeaddrs[] = { |
| 369 | 0xc0000, 0xd0000, 0xe0000, 0xf0000, |
| 370 | 0x80000000, 0x80010000, 0x80020000, 0x80030000, |
| 371 | 0x40000000, 0x40010000, 0x40020000, 0x40030000, |
| 372 | 0xc0000000, 0xc0010000, 0xc0020000, 0xc0030000, |
| 373 | 0xff000000, 0xff010000, 0xff020000, 0xff030000, |
| 374 | }; |
| 375 | |
Tobias Klauser | fe97107 | 2006-01-09 20:54:02 -0800 | [diff] [blame] | 376 | static int stli_eisamempsize = ARRAY_SIZE(stli_eisamemprobeaddrs); |
Jiri Slaby | a00f33f | 2006-12-08 02:39:20 -0800 | [diff] [blame] | 377 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | |
| 379 | /* |
| 380 | * Define the Stallion PCI vendor and device IDs. |
| 381 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | #ifndef PCI_DEVICE_ID_ECRA |
| 383 | #define PCI_DEVICE_ID_ECRA 0x0004 |
| 384 | #endif |
| 385 | |
| 386 | static struct pci_device_id istallion_pci_tbl[] = { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 387 | { PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECRA), }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | { 0 } |
| 389 | }; |
| 390 | MODULE_DEVICE_TABLE(pci, istallion_pci_tbl); |
| 391 | |
Jiri Slaby | 845bead | 2006-12-08 02:39:17 -0800 | [diff] [blame] | 392 | static struct pci_driver stli_pcidriver; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | |
| 394 | /*****************************************************************************/ |
| 395 | |
| 396 | /* |
| 397 | * Hardware configuration info for ECP boards. These defines apply |
| 398 | * to the directly accessible io ports of the ECP. There is a set of |
| 399 | * defines for each ECP board type, ISA, EISA, MCA and PCI. |
| 400 | */ |
| 401 | #define ECP_IOSIZE 4 |
| 402 | |
| 403 | #define ECP_MEMSIZE (128 * 1024) |
| 404 | #define ECP_PCIMEMSIZE (256 * 1024) |
| 405 | |
| 406 | #define ECP_ATPAGESIZE (4 * 1024) |
| 407 | #define ECP_MCPAGESIZE (4 * 1024) |
| 408 | #define ECP_EIPAGESIZE (64 * 1024) |
| 409 | #define ECP_PCIPAGESIZE (64 * 1024) |
| 410 | |
| 411 | #define STL_EISAID 0x8c4e |
| 412 | |
| 413 | /* |
| 414 | * Important defines for the ISA class of ECP board. |
| 415 | */ |
| 416 | #define ECP_ATIREG 0 |
| 417 | #define ECP_ATCONFR 1 |
| 418 | #define ECP_ATMEMAR 2 |
| 419 | #define ECP_ATMEMPR 3 |
| 420 | #define ECP_ATSTOP 0x1 |
| 421 | #define ECP_ATINTENAB 0x10 |
| 422 | #define ECP_ATENABLE 0x20 |
| 423 | #define ECP_ATDISABLE 0x00 |
| 424 | #define ECP_ATADDRMASK 0x3f000 |
| 425 | #define ECP_ATADDRSHFT 12 |
| 426 | |
| 427 | /* |
| 428 | * Important defines for the EISA class of ECP board. |
| 429 | */ |
| 430 | #define ECP_EIIREG 0 |
| 431 | #define ECP_EIMEMARL 1 |
| 432 | #define ECP_EICONFR 2 |
| 433 | #define ECP_EIMEMARH 3 |
| 434 | #define ECP_EIENABLE 0x1 |
| 435 | #define ECP_EIDISABLE 0x0 |
| 436 | #define ECP_EISTOP 0x4 |
| 437 | #define ECP_EIEDGE 0x00 |
| 438 | #define ECP_EILEVEL 0x80 |
| 439 | #define ECP_EIADDRMASKL 0x00ff0000 |
| 440 | #define ECP_EIADDRSHFTL 16 |
| 441 | #define ECP_EIADDRMASKH 0xff000000 |
| 442 | #define ECP_EIADDRSHFTH 24 |
| 443 | #define ECP_EIBRDENAB 0xc84 |
| 444 | |
| 445 | #define ECP_EISAID 0x4 |
| 446 | |
| 447 | /* |
| 448 | * Important defines for the Micro-channel class of ECP board. |
| 449 | * (It has a lot in common with the ISA boards.) |
| 450 | */ |
| 451 | #define ECP_MCIREG 0 |
| 452 | #define ECP_MCCONFR 1 |
| 453 | #define ECP_MCSTOP 0x20 |
| 454 | #define ECP_MCENABLE 0x80 |
| 455 | #define ECP_MCDISABLE 0x00 |
| 456 | |
| 457 | /* |
| 458 | * Important defines for the PCI class of ECP board. |
| 459 | * (It has a lot in common with the other ECP boards.) |
| 460 | */ |
| 461 | #define ECP_PCIIREG 0 |
| 462 | #define ECP_PCICONFR 1 |
| 463 | #define ECP_PCISTOP 0x01 |
| 464 | |
| 465 | /* |
| 466 | * Hardware configuration info for ONboard and Brumby boards. These |
| 467 | * defines apply to the directly accessible io ports of these boards. |
| 468 | */ |
| 469 | #define ONB_IOSIZE 16 |
| 470 | #define ONB_MEMSIZE (64 * 1024) |
| 471 | #define ONB_ATPAGESIZE (64 * 1024) |
| 472 | #define ONB_MCPAGESIZE (64 * 1024) |
| 473 | #define ONB_EIMEMSIZE (128 * 1024) |
| 474 | #define ONB_EIPAGESIZE (64 * 1024) |
| 475 | |
| 476 | /* |
| 477 | * Important defines for the ISA class of ONboard board. |
| 478 | */ |
| 479 | #define ONB_ATIREG 0 |
| 480 | #define ONB_ATMEMAR 1 |
| 481 | #define ONB_ATCONFR 2 |
| 482 | #define ONB_ATSTOP 0x4 |
| 483 | #define ONB_ATENABLE 0x01 |
| 484 | #define ONB_ATDISABLE 0x00 |
| 485 | #define ONB_ATADDRMASK 0xff0000 |
| 486 | #define ONB_ATADDRSHFT 16 |
| 487 | |
| 488 | #define ONB_MEMENABLO 0 |
| 489 | #define ONB_MEMENABHI 0x02 |
| 490 | |
| 491 | /* |
| 492 | * Important defines for the EISA class of ONboard board. |
| 493 | */ |
| 494 | #define ONB_EIIREG 0 |
| 495 | #define ONB_EIMEMARL 1 |
| 496 | #define ONB_EICONFR 2 |
| 497 | #define ONB_EIMEMARH 3 |
| 498 | #define ONB_EIENABLE 0x1 |
| 499 | #define ONB_EIDISABLE 0x0 |
| 500 | #define ONB_EISTOP 0x4 |
| 501 | #define ONB_EIEDGE 0x00 |
| 502 | #define ONB_EILEVEL 0x80 |
| 503 | #define ONB_EIADDRMASKL 0x00ff0000 |
| 504 | #define ONB_EIADDRSHFTL 16 |
| 505 | #define ONB_EIADDRMASKH 0xff000000 |
| 506 | #define ONB_EIADDRSHFTH 24 |
| 507 | #define ONB_EIBRDENAB 0xc84 |
| 508 | |
| 509 | #define ONB_EISAID 0x1 |
| 510 | |
| 511 | /* |
| 512 | * Important defines for the Brumby boards. They are pretty simple, |
| 513 | * there is not much that is programmably configurable. |
| 514 | */ |
| 515 | #define BBY_IOSIZE 16 |
| 516 | #define BBY_MEMSIZE (64 * 1024) |
| 517 | #define BBY_PAGESIZE (16 * 1024) |
| 518 | |
| 519 | #define BBY_ATIREG 0 |
| 520 | #define BBY_ATCONFR 1 |
| 521 | #define BBY_ATSTOP 0x4 |
| 522 | |
| 523 | /* |
| 524 | * Important defines for the Stallion boards. They are pretty simple, |
| 525 | * there is not much that is programmably configurable. |
| 526 | */ |
| 527 | #define STAL_IOSIZE 16 |
| 528 | #define STAL_MEMSIZE (64 * 1024) |
| 529 | #define STAL_PAGESIZE (64 * 1024) |
| 530 | |
| 531 | /* |
| 532 | * Define the set of status register values for EasyConnection panels. |
| 533 | * The signature will return with the status value for each panel. From |
| 534 | * this we can determine what is attached to the board - before we have |
| 535 | * actually down loaded any code to it. |
| 536 | */ |
| 537 | #define ECH_PNLSTATUS 2 |
| 538 | #define ECH_PNL16PORT 0x20 |
| 539 | #define ECH_PNLIDMASK 0x07 |
| 540 | #define ECH_PNLXPID 0x40 |
| 541 | #define ECH_PNLINTRPEND 0x80 |
| 542 | |
| 543 | /* |
| 544 | * Define some macros to do things to the board. Even those these boards |
| 545 | * are somewhat related there is often significantly different ways of |
| 546 | * doing some operation on it (like enable, paging, reset, etc). So each |
| 547 | * board class has a set of functions which do the commonly required |
| 548 | * operations. The macros below basically just call these functions, |
| 549 | * generally checking for a NULL function - which means that the board |
| 550 | * needs nothing done to it to achieve this operation! |
| 551 | */ |
| 552 | #define EBRDINIT(brdp) \ |
| 553 | if (brdp->init != NULL) \ |
| 554 | (* brdp->init)(brdp) |
| 555 | |
| 556 | #define EBRDENABLE(brdp) \ |
| 557 | if (brdp->enable != NULL) \ |
| 558 | (* brdp->enable)(brdp); |
| 559 | |
| 560 | #define EBRDDISABLE(brdp) \ |
| 561 | if (brdp->disable != NULL) \ |
| 562 | (* brdp->disable)(brdp); |
| 563 | |
| 564 | #define EBRDINTR(brdp) \ |
| 565 | if (brdp->intr != NULL) \ |
| 566 | (* brdp->intr)(brdp); |
| 567 | |
| 568 | #define EBRDRESET(brdp) \ |
| 569 | if (brdp->reset != NULL) \ |
| 570 | (* brdp->reset)(brdp); |
| 571 | |
| 572 | #define EBRDGETMEMPTR(brdp,offset) \ |
| 573 | (* brdp->getmemptr)(brdp, offset, __LINE__) |
| 574 | |
| 575 | /* |
| 576 | * Define the maximal baud rate, and the default baud base for ports. |
| 577 | */ |
| 578 | #define STL_MAXBAUD 460800 |
| 579 | #define STL_BAUDBASE 115200 |
| 580 | #define STL_CLOSEDELAY (5 * HZ / 10) |
| 581 | |
| 582 | /*****************************************************************************/ |
| 583 | |
| 584 | /* |
| 585 | * Define macros to extract a brd or port number from a minor number. |
| 586 | */ |
| 587 | #define MINOR2BRD(min) (((min) & 0xc0) >> 6) |
| 588 | #define MINOR2PORT(min) ((min) & 0x3f) |
| 589 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | /*****************************************************************************/ |
| 591 | |
| 592 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | * Prototype all functions in this driver! |
| 594 | */ |
| 595 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 596 | static int stli_parsebrd(struct stlconf *confp, char **argp); |
Adrian Bunk | 672b271 | 2006-06-30 01:55:30 -0700 | [diff] [blame] | 597 | static int stli_init(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | static int stli_open(struct tty_struct *tty, struct file *filp); |
| 599 | static void stli_close(struct tty_struct *tty, struct file *filp); |
| 600 | static int stli_write(struct tty_struct *tty, const unsigned char *buf, int count); |
| 601 | static void stli_putchar(struct tty_struct *tty, unsigned char ch); |
| 602 | static void stli_flushchars(struct tty_struct *tty); |
| 603 | static int stli_writeroom(struct tty_struct *tty); |
| 604 | static int stli_charsinbuffer(struct tty_struct *tty); |
| 605 | static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg); |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 606 | static void stli_settermios(struct tty_struct *tty, struct ktermios *old); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | static void stli_throttle(struct tty_struct *tty); |
| 608 | static void stli_unthrottle(struct tty_struct *tty); |
| 609 | static void stli_stop(struct tty_struct *tty); |
| 610 | static void stli_start(struct tty_struct *tty); |
| 611 | static void stli_flushbuffer(struct tty_struct *tty); |
| 612 | static void stli_breakctl(struct tty_struct *tty, int state); |
| 613 | static void stli_waituntilsent(struct tty_struct *tty, int timeout); |
| 614 | static void stli_sendxchar(struct tty_struct *tty, char ch); |
| 615 | static void stli_hangup(struct tty_struct *tty); |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 616 | static int stli_portinfo(struct stlibrd *brdp, struct stliport *portp, int portnr, char *pos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 618 | static int stli_brdinit(struct stlibrd *brdp); |
| 619 | static int stli_startbrd(struct stlibrd *brdp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp); |
| 621 | static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp); |
| 622 | static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg); |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 623 | static void stli_brdpoll(struct stlibrd *brdp, cdkhdr_t __iomem *hdrp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | static void stli_poll(unsigned long arg); |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 625 | static int stli_hostcmd(struct stlibrd *brdp, struct stliport *portp); |
| 626 | static int stli_initopen(struct stlibrd *brdp, struct stliport *portp); |
| 627 | static int stli_rawopen(struct stlibrd *brdp, struct stliport *portp, unsigned long arg, int wait); |
| 628 | static int stli_rawclose(struct stlibrd *brdp, struct stliport *portp, unsigned long arg, int wait); |
| 629 | static int stli_waitcarrier(struct stlibrd *brdp, struct stliport *portp, struct file *filp); |
Al Viro | 3e577a8 | 2006-12-06 18:41:45 +0000 | [diff] [blame] | 630 | static void stli_dohangup(struct work_struct *); |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 631 | static int stli_setport(struct stliport *portp); |
| 632 | static int stli_cmdwait(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback); |
| 633 | static void stli_sendcmd(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback); |
| 634 | static void __stli_sendcmd(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback); |
| 635 | static void stli_dodelaycmd(struct stliport *portp, cdkctrl_t __iomem *cp); |
| 636 | static void stli_mkasyport(struct stliport *portp, asyport_t *pp, struct ktermios *tiosp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts); |
| 638 | static long stli_mktiocm(unsigned long sigvalue); |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 639 | static void stli_read(struct stlibrd *brdp, struct stliport *portp); |
| 640 | static int stli_getserial(struct stliport *portp, struct serial_struct __user *sp); |
| 641 | static int stli_setserial(struct stliport *portp, struct serial_struct __user *sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | static int stli_getbrdstats(combrd_t __user *bp); |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 643 | static int stli_getportstats(struct stliport *portp, comstats_t __user *cp); |
| 644 | static int stli_portcmdstats(struct stliport *portp); |
| 645 | static int stli_clrportstats(struct stliport *portp, comstats_t __user *cp); |
| 646 | static int stli_getportstruct(struct stliport __user *arg); |
| 647 | static int stli_getbrdstruct(struct stlibrd __user *arg); |
| 648 | static struct stlibrd *stli_allocbrd(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 650 | static void stli_ecpinit(struct stlibrd *brdp); |
| 651 | static void stli_ecpenable(struct stlibrd *brdp); |
| 652 | static void stli_ecpdisable(struct stlibrd *brdp); |
| 653 | static void __iomem *stli_ecpgetmemptr(struct stlibrd *brdp, unsigned long offset, int line); |
| 654 | static void stli_ecpreset(struct stlibrd *brdp); |
| 655 | static void stli_ecpintr(struct stlibrd *brdp); |
| 656 | static void stli_ecpeiinit(struct stlibrd *brdp); |
| 657 | static void stli_ecpeienable(struct stlibrd *brdp); |
| 658 | static void stli_ecpeidisable(struct stlibrd *brdp); |
| 659 | static void __iomem *stli_ecpeigetmemptr(struct stlibrd *brdp, unsigned long offset, int line); |
| 660 | static void stli_ecpeireset(struct stlibrd *brdp); |
| 661 | static void stli_ecpmcenable(struct stlibrd *brdp); |
| 662 | static void stli_ecpmcdisable(struct stlibrd *brdp); |
| 663 | static void __iomem *stli_ecpmcgetmemptr(struct stlibrd *brdp, unsigned long offset, int line); |
| 664 | static void stli_ecpmcreset(struct stlibrd *brdp); |
| 665 | static void stli_ecppciinit(struct stlibrd *brdp); |
| 666 | static void __iomem *stli_ecppcigetmemptr(struct stlibrd *brdp, unsigned long offset, int line); |
| 667 | static void stli_ecppcireset(struct stlibrd *brdp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 669 | static void stli_onbinit(struct stlibrd *brdp); |
| 670 | static void stli_onbenable(struct stlibrd *brdp); |
| 671 | static void stli_onbdisable(struct stlibrd *brdp); |
| 672 | static void __iomem *stli_onbgetmemptr(struct stlibrd *brdp, unsigned long offset, int line); |
| 673 | static void stli_onbreset(struct stlibrd *brdp); |
| 674 | static void stli_onbeinit(struct stlibrd *brdp); |
| 675 | static void stli_onbeenable(struct stlibrd *brdp); |
| 676 | static void stli_onbedisable(struct stlibrd *brdp); |
| 677 | static void __iomem *stli_onbegetmemptr(struct stlibrd *brdp, unsigned long offset, int line); |
| 678 | static void stli_onbereset(struct stlibrd *brdp); |
| 679 | static void stli_bbyinit(struct stlibrd *brdp); |
| 680 | static void __iomem *stli_bbygetmemptr(struct stlibrd *brdp, unsigned long offset, int line); |
| 681 | static void stli_bbyreset(struct stlibrd *brdp); |
| 682 | static void stli_stalinit(struct stlibrd *brdp); |
| 683 | static void __iomem *stli_stalgetmemptr(struct stlibrd *brdp, unsigned long offset, int line); |
| 684 | static void stli_stalreset(struct stlibrd *brdp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | |
Jiri Slaby | 1328d73 | 2006-12-08 02:39:19 -0800 | [diff] [blame] | 686 | static struct stliport *stli_getport(unsigned int brdnr, unsigned int panelnr, unsigned int portnr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 688 | static int stli_initecp(struct stlibrd *brdp); |
| 689 | static int stli_initonb(struct stlibrd *brdp); |
Jiri Slaby | a00f33f | 2006-12-08 02:39:20 -0800 | [diff] [blame] | 690 | #if STLI_EISAPROBE != 0 |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 691 | static int stli_eisamemprobe(struct stlibrd *brdp); |
Jiri Slaby | a00f33f | 2006-12-08 02:39:20 -0800 | [diff] [blame] | 692 | #endif |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 693 | static int stli_initports(struct stlibrd *brdp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | /*****************************************************************************/ |
| 696 | |
| 697 | /* |
| 698 | * Define the driver info for a user level shared memory device. This |
| 699 | * device will work sort of like the /dev/kmem device - except that it |
| 700 | * will give access to the shared memory on the Stallion intelligent |
| 701 | * board. This is also a very useful debugging tool. |
| 702 | */ |
Arjan van de Ven | 62322d2 | 2006-07-03 00:24:21 -0700 | [diff] [blame] | 703 | static const struct file_operations stli_fsiomem = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | .owner = THIS_MODULE, |
| 705 | .read = stli_memread, |
| 706 | .write = stli_memwrite, |
| 707 | .ioctl = stli_memioctl, |
| 708 | }; |
| 709 | |
| 710 | /*****************************************************************************/ |
| 711 | |
| 712 | /* |
| 713 | * Define a timer_list entry for our poll routine. The slave board |
| 714 | * is polled every so often to see if anything needs doing. This is |
| 715 | * much cheaper on host cpu than using interrupts. It turns out to |
| 716 | * not increase character latency by much either... |
| 717 | */ |
Ingo Molnar | 8d06afa | 2005-09-09 13:10:40 -0700 | [diff] [blame] | 718 | static DEFINE_TIMER(stli_timerlist, stli_poll, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | |
| 720 | static int stli_timeron; |
| 721 | |
| 722 | /* |
| 723 | * Define the calculation for the timeout routine. |
| 724 | */ |
| 725 | #define STLI_TIMEOUT (jiffies + 1) |
| 726 | |
| 727 | /*****************************************************************************/ |
| 728 | |
gregkh@suse.de | ca8eca6 | 2005-03-23 09:53:09 -0800 | [diff] [blame] | 729 | static struct class *istallion_class; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 731 | static void stli_cleanup_ports(struct stlibrd *brdp) |
Jiri Slaby | 845bead | 2006-12-08 02:39:17 -0800 | [diff] [blame] | 732 | { |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 733 | struct stliport *portp; |
Jiri Slaby | 845bead | 2006-12-08 02:39:17 -0800 | [diff] [blame] | 734 | unsigned int j; |
| 735 | |
| 736 | for (j = 0; j < STL_MAXPORTS; j++) { |
| 737 | portp = brdp->ports[j]; |
| 738 | if (portp != NULL) { |
| 739 | if (portp->tty != NULL) |
| 740 | tty_hangup(portp->tty); |
| 741 | kfree(portp); |
| 742 | } |
| 743 | } |
| 744 | } |
| 745 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | /* |
| 747 | * Loadable module initialization stuff. |
| 748 | */ |
| 749 | |
| 750 | static int __init istallion_module_init(void) |
| 751 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | stli_init(); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 753 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | /*****************************************************************************/ |
| 757 | |
| 758 | static void __exit istallion_module_exit(void) |
| 759 | { |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 760 | struct stlibrd *brdp; |
Jiri Slaby | 1328d73 | 2006-12-08 02:39:19 -0800 | [diff] [blame] | 761 | unsigned int j; |
Jiri Slaby | 845bead | 2006-12-08 02:39:17 -0800 | [diff] [blame] | 762 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | printk(KERN_INFO "Unloading %s: version %s\n", stli_drvtitle, |
| 765 | stli_drvversion); |
| 766 | |
Jiri Slaby | 845bead | 2006-12-08 02:39:17 -0800 | [diff] [blame] | 767 | pci_unregister_driver(&stli_pcidriver); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 768 | /* |
| 769 | * Free up all allocated resources used by the ports. This includes |
| 770 | * memory and interrupts. |
| 771 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | if (stli_timeron) { |
| 773 | stli_timeron = 0; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 774 | del_timer_sync(&stli_timerlist); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | i = tty_unregister_driver(stli_serial); |
| 778 | if (i) { |
| 779 | printk("STALLION: failed to un-register tty driver, " |
| 780 | "errno=%d\n", -i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | return; |
| 782 | } |
| 783 | put_tty_driver(stli_serial); |
Jiri Slaby | 1328d73 | 2006-12-08 02:39:19 -0800 | [diff] [blame] | 784 | for (j = 0; j < 4; j++) |
| 785 | class_device_destroy(istallion_class, MKDEV(STL_SIOMEMMAJOR, j)); |
gregkh@suse.de | ca8eca6 | 2005-03-23 09:53:09 -0800 | [diff] [blame] | 786 | class_destroy(istallion_class); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem"))) |
| 788 | printk("STALLION: failed to un-register serial memory device, " |
| 789 | "errno=%d\n", -i); |
Jesper Juhl | 735d566 | 2005-11-07 01:01:29 -0800 | [diff] [blame] | 790 | |
Jesper Juhl | 735d566 | 2005-11-07 01:01:29 -0800 | [diff] [blame] | 791 | kfree(stli_txcookbuf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | |
Jiri Slaby | 1328d73 | 2006-12-08 02:39:19 -0800 | [diff] [blame] | 793 | for (j = 0; (j < stli_nrbrds); j++) { |
| 794 | if ((brdp = stli_brds[j]) == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | continue; |
Jiri Slaby | 845bead | 2006-12-08 02:39:17 -0800 | [diff] [blame] | 796 | |
| 797 | stli_cleanup_ports(brdp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | |
| 799 | iounmap(brdp->membase); |
| 800 | if (brdp->iosize > 0) |
| 801 | release_region(brdp->iobase, brdp->iosize); |
| 802 | kfree(brdp); |
Jiri Slaby | 1328d73 | 2006-12-08 02:39:19 -0800 | [diff] [blame] | 803 | stli_brds[j] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | } |
| 806 | |
| 807 | module_init(istallion_module_init); |
| 808 | module_exit(istallion_module_exit); |
| 809 | |
| 810 | /*****************************************************************************/ |
| 811 | |
| 812 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | * Parse the supplied argument string, into the board conf struct. |
| 814 | */ |
| 815 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 816 | static int stli_parsebrd(struct stlconf *confp, char **argp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | { |
Jiri Slaby | 1328d73 | 2006-12-08 02:39:19 -0800 | [diff] [blame] | 818 | unsigned int i; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 819 | char *sp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 821 | if (argp[0] == NULL || *argp[0] == 0) |
| 822 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | |
| 824 | for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++) |
Jiri Slaby | a3f8d9d | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 825 | *sp = tolower(*sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | |
Tobias Klauser | fe97107 | 2006-01-09 20:54:02 -0800 | [diff] [blame] | 827 | for (i = 0; i < ARRAY_SIZE(stli_brdstr); i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | if (strcmp(stli_brdstr[i].name, argp[0]) == 0) |
| 829 | break; |
| 830 | } |
Tobias Klauser | fe97107 | 2006-01-09 20:54:02 -0800 | [diff] [blame] | 831 | if (i == ARRAY_SIZE(stli_brdstr)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | printk("STALLION: unknown board name, %s?\n", argp[0]); |
Tobias Klauser | fe97107 | 2006-01-09 20:54:02 -0800 | [diff] [blame] | 833 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | confp->brdtype = stli_brdstr[i].type; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 837 | if (argp[1] != NULL && *argp[1] != 0) |
Jiri Slaby | a3f8d9d | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 838 | confp->ioaddr1 = simple_strtoul(argp[1], NULL, 0); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 839 | if (argp[2] != NULL && *argp[2] != 0) |
Jiri Slaby | a3f8d9d | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 840 | confp->memaddr = simple_strtoul(argp[2], NULL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | return(1); |
| 842 | } |
| 843 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | /*****************************************************************************/ |
| 845 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | static int stli_open(struct tty_struct *tty, struct file *filp) |
| 847 | { |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 848 | struct stlibrd *brdp; |
| 849 | struct stliport *portp; |
Jiri Slaby | 1328d73 | 2006-12-08 02:39:19 -0800 | [diff] [blame] | 850 | unsigned int minordev, brdnr, portnr; |
| 851 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | |
| 853 | minordev = tty->index; |
| 854 | brdnr = MINOR2BRD(minordev); |
| 855 | if (brdnr >= stli_nrbrds) |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 856 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | brdp = stli_brds[brdnr]; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 858 | if (brdp == NULL) |
| 859 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | if ((brdp->state & BST_STARTED) == 0) |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 861 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | portnr = MINOR2PORT(minordev); |
Jiri Slaby | 1328d73 | 2006-12-08 02:39:19 -0800 | [diff] [blame] | 863 | if (portnr > brdp->nrports) |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 864 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | |
| 866 | portp = brdp->ports[portnr]; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 867 | if (portp == NULL) |
| 868 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | if (portp->devnr < 1) |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 870 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | |
| 872 | |
| 873 | /* |
| 874 | * Check if this port is in the middle of closing. If so then wait |
| 875 | * until it is closed then return error status based on flag settings. |
| 876 | * The sleep here does not need interrupt protection since the wakeup |
| 877 | * for it is done with the same context. |
| 878 | */ |
| 879 | if (portp->flags & ASYNC_CLOSING) { |
| 880 | interruptible_sleep_on(&portp->close_wait); |
| 881 | if (portp->flags & ASYNC_HUP_NOTIFY) |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 882 | return -EAGAIN; |
| 883 | return -ERESTARTSYS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | /* |
| 887 | * On the first open of the device setup the port hardware, and |
| 888 | * initialize the per port data structure. Since initializing the port |
| 889 | * requires several commands to the board we will need to wait for any |
| 890 | * other open that is already initializing the port. |
| 891 | */ |
| 892 | portp->tty = tty; |
| 893 | tty->driver_data = portp; |
| 894 | portp->refcount++; |
| 895 | |
| 896 | wait_event_interruptible(portp->raw_wait, |
| 897 | !test_bit(ST_INITIALIZING, &portp->state)); |
| 898 | if (signal_pending(current)) |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 899 | return -ERESTARTSYS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | |
| 901 | if ((portp->flags & ASYNC_INITIALIZED) == 0) { |
| 902 | set_bit(ST_INITIALIZING, &portp->state); |
| 903 | if ((rc = stli_initopen(brdp, portp)) >= 0) { |
| 904 | portp->flags |= ASYNC_INITIALIZED; |
| 905 | clear_bit(TTY_IO_ERROR, &tty->flags); |
| 906 | } |
| 907 | clear_bit(ST_INITIALIZING, &portp->state); |
| 908 | wake_up_interruptible(&portp->raw_wait); |
| 909 | if (rc < 0) |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 910 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | } |
| 912 | |
| 913 | /* |
| 914 | * Check if this port is in the middle of closing. If so then wait |
| 915 | * until it is closed then return error status, based on flag settings. |
| 916 | * The sleep here does not need interrupt protection since the wakeup |
| 917 | * for it is done with the same context. |
| 918 | */ |
| 919 | if (portp->flags & ASYNC_CLOSING) { |
| 920 | interruptible_sleep_on(&portp->close_wait); |
| 921 | if (portp->flags & ASYNC_HUP_NOTIFY) |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 922 | return -EAGAIN; |
| 923 | return -ERESTARTSYS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | /* |
| 927 | * Based on type of open being done check if it can overlap with any |
| 928 | * previous opens still in effect. If we are a normal serial device |
| 929 | * then also we might have to wait for carrier. |
| 930 | */ |
| 931 | if (!(filp->f_flags & O_NONBLOCK)) { |
| 932 | if ((rc = stli_waitcarrier(brdp, portp, filp)) != 0) |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 933 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | } |
| 935 | portp->flags |= ASYNC_NORMAL_ACTIVE; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 936 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | } |
| 938 | |
| 939 | /*****************************************************************************/ |
| 940 | |
| 941 | static void stli_close(struct tty_struct *tty, struct file *filp) |
| 942 | { |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 943 | struct stlibrd *brdp; |
| 944 | struct stliport *portp; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 945 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | |
| 947 | portp = tty->driver_data; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 948 | if (portp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | return; |
| 950 | |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 951 | spin_lock_irqsave(&stli_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | if (tty_hung_up_p(filp)) { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 953 | spin_unlock_irqrestore(&stli_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | return; |
| 955 | } |
| 956 | if ((tty->count == 1) && (portp->refcount != 1)) |
| 957 | portp->refcount = 1; |
| 958 | if (portp->refcount-- > 1) { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 959 | spin_unlock_irqrestore(&stli_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | return; |
| 961 | } |
| 962 | |
| 963 | portp->flags |= ASYNC_CLOSING; |
| 964 | |
| 965 | /* |
| 966 | * May want to wait for data to drain before closing. The BUSY flag |
| 967 | * keeps track of whether we are still transmitting or not. It is |
| 968 | * updated by messages from the slave - indicating when all chars |
| 969 | * really have drained. |
| 970 | */ |
| 971 | if (tty == stli_txcooktty) |
| 972 | stli_flushchars(tty); |
| 973 | tty->closing = 1; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 974 | spin_unlock_irqrestore(&stli_lock, flags); |
| 975 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE) |
| 977 | tty_wait_until_sent(tty, portp->closing_wait); |
| 978 | |
| 979 | portp->flags &= ~ASYNC_INITIALIZED; |
| 980 | brdp = stli_brds[portp->brdnr]; |
| 981 | stli_rawclose(brdp, portp, 0, 0); |
| 982 | if (tty->termios->c_cflag & HUPCL) { |
| 983 | stli_mkasysigs(&portp->asig, 0, 0); |
| 984 | if (test_bit(ST_CMDING, &portp->state)) |
| 985 | set_bit(ST_DOSIGS, &portp->state); |
| 986 | else |
| 987 | stli_sendcmd(brdp, portp, A_SETSIGNALS, &portp->asig, |
| 988 | sizeof(asysigs_t), 0); |
| 989 | } |
| 990 | clear_bit(ST_TXBUSY, &portp->state); |
| 991 | clear_bit(ST_RXSTOP, &portp->state); |
| 992 | set_bit(TTY_IO_ERROR, &tty->flags); |
| 993 | if (tty->ldisc.flush_buffer) |
| 994 | (tty->ldisc.flush_buffer)(tty); |
| 995 | set_bit(ST_DOFLUSHRX, &portp->state); |
| 996 | stli_flushbuffer(tty); |
| 997 | |
| 998 | tty->closing = 0; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 999 | portp->tty = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | |
| 1001 | if (portp->openwaitcnt) { |
| 1002 | if (portp->close_delay) |
| 1003 | msleep_interruptible(jiffies_to_msecs(portp->close_delay)); |
| 1004 | wake_up_interruptible(&portp->open_wait); |
| 1005 | } |
| 1006 | |
| 1007 | portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING); |
| 1008 | wake_up_interruptible(&portp->close_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | /*****************************************************************************/ |
| 1012 | |
| 1013 | /* |
| 1014 | * Carry out first open operations on a port. This involves a number of |
| 1015 | * commands to be sent to the slave. We need to open the port, set the |
| 1016 | * notification events, set the initial port settings, get and set the |
| 1017 | * initial signal values. We sleep and wait in between each one. But |
| 1018 | * this still all happens pretty quickly. |
| 1019 | */ |
| 1020 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 1021 | static int stli_initopen(struct stlibrd *brdp, struct stliport *portp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1023 | struct tty_struct *tty; |
| 1024 | asynotify_t nt; |
| 1025 | asyport_t aport; |
| 1026 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | |
| 1028 | if ((rc = stli_rawopen(brdp, portp, 0, 1)) < 0) |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1029 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | |
| 1031 | memset(&nt, 0, sizeof(asynotify_t)); |
| 1032 | nt.data = (DT_TXLOW | DT_TXEMPTY | DT_RXBUSY | DT_RXBREAK); |
| 1033 | nt.signal = SG_DCD; |
| 1034 | if ((rc = stli_cmdwait(brdp, portp, A_SETNOTIFY, &nt, |
| 1035 | sizeof(asynotify_t), 0)) < 0) |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1036 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | |
| 1038 | tty = portp->tty; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1039 | if (tty == NULL) |
| 1040 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | stli_mkasyport(portp, &aport, tty->termios); |
| 1042 | if ((rc = stli_cmdwait(brdp, portp, A_SETPORT, &aport, |
| 1043 | sizeof(asyport_t), 0)) < 0) |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1044 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | |
| 1046 | set_bit(ST_GETSIGS, &portp->state); |
| 1047 | if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS, &portp->asig, |
| 1048 | sizeof(asysigs_t), 1)) < 0) |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1049 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | if (test_and_clear_bit(ST_GETSIGS, &portp->state)) |
| 1051 | portp->sigs = stli_mktiocm(portp->asig.sigvalue); |
| 1052 | stli_mkasysigs(&portp->asig, 1, 1); |
| 1053 | if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig, |
| 1054 | sizeof(asysigs_t), 0)) < 0) |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1055 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1057 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1058 | } |
| 1059 | |
| 1060 | /*****************************************************************************/ |
| 1061 | |
| 1062 | /* |
| 1063 | * Send an open message to the slave. This will sleep waiting for the |
| 1064 | * acknowledgement, so must have user context. We need to co-ordinate |
| 1065 | * with close events here, since we don't want open and close events |
| 1066 | * to overlap. |
| 1067 | */ |
| 1068 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 1069 | static int stli_rawopen(struct stlibrd *brdp, struct stliport *portp, unsigned long arg, int wait) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1071 | cdkhdr_t __iomem *hdrp; |
| 1072 | cdkctrl_t __iomem *cp; |
| 1073 | unsigned char __iomem *bits; |
| 1074 | unsigned long flags; |
| 1075 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | |
| 1077 | /* |
| 1078 | * Send a message to the slave to open this port. |
| 1079 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1080 | |
| 1081 | /* |
| 1082 | * Slave is already closing this port. This can happen if a hangup |
| 1083 | * occurs on this port. So we must wait until it is complete. The |
| 1084 | * order of opens and closes may not be preserved across shared |
| 1085 | * memory, so we must wait until it is complete. |
| 1086 | */ |
| 1087 | wait_event_interruptible(portp->raw_wait, |
| 1088 | !test_bit(ST_CLOSING, &portp->state)); |
| 1089 | if (signal_pending(current)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | return -ERESTARTSYS; |
| 1091 | } |
| 1092 | |
| 1093 | /* |
| 1094 | * Everything is ready now, so write the open message into shared |
| 1095 | * memory. Once the message is in set the service bits to say that |
| 1096 | * this port wants service. |
| 1097 | */ |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1098 | spin_lock_irqsave(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | EBRDENABLE(brdp); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1100 | cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl; |
| 1101 | writel(arg, &cp->openarg); |
| 1102 | writeb(1, &cp->open); |
| 1103 | hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR); |
| 1104 | bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | portp->portidx; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1106 | writeb(readb(bits) | portp->portbit, bits); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1107 | EBRDDISABLE(brdp); |
| 1108 | |
| 1109 | if (wait == 0) { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1110 | spin_unlock_irqrestore(&brd_lock, flags); |
| 1111 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | } |
| 1113 | |
| 1114 | /* |
| 1115 | * Slave is in action, so now we must wait for the open acknowledgment |
| 1116 | * to come back. |
| 1117 | */ |
| 1118 | rc = 0; |
| 1119 | set_bit(ST_OPENING, &portp->state); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1120 | spin_unlock_irqrestore(&brd_lock, flags); |
| 1121 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | wait_event_interruptible(portp->raw_wait, |
| 1123 | !test_bit(ST_OPENING, &portp->state)); |
| 1124 | if (signal_pending(current)) |
| 1125 | rc = -ERESTARTSYS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | |
| 1127 | if ((rc == 0) && (portp->rc != 0)) |
| 1128 | rc = -EIO; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1129 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1130 | } |
| 1131 | |
| 1132 | /*****************************************************************************/ |
| 1133 | |
| 1134 | /* |
| 1135 | * Send a close message to the slave. Normally this will sleep waiting |
| 1136 | * for the acknowledgement, but if wait parameter is 0 it will not. If |
| 1137 | * wait is true then must have user context (to sleep). |
| 1138 | */ |
| 1139 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 1140 | static int stli_rawclose(struct stlibrd *brdp, struct stliport *portp, unsigned long arg, int wait) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1141 | { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1142 | cdkhdr_t __iomem *hdrp; |
| 1143 | cdkctrl_t __iomem *cp; |
| 1144 | unsigned char __iomem *bits; |
| 1145 | unsigned long flags; |
| 1146 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | |
| 1148 | /* |
| 1149 | * Slave is already closing this port. This can happen if a hangup |
| 1150 | * occurs on this port. |
| 1151 | */ |
| 1152 | if (wait) { |
| 1153 | wait_event_interruptible(portp->raw_wait, |
| 1154 | !test_bit(ST_CLOSING, &portp->state)); |
| 1155 | if (signal_pending(current)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 | return -ERESTARTSYS; |
| 1157 | } |
| 1158 | } |
| 1159 | |
| 1160 | /* |
| 1161 | * Write the close command into shared memory. |
| 1162 | */ |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1163 | spin_lock_irqsave(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | EBRDENABLE(brdp); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1165 | cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl; |
| 1166 | writel(arg, &cp->closearg); |
| 1167 | writeb(1, &cp->close); |
| 1168 | hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR); |
| 1169 | bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | portp->portidx; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1171 | writeb(readb(bits) |portp->portbit, bits); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | EBRDDISABLE(brdp); |
| 1173 | |
| 1174 | set_bit(ST_CLOSING, &portp->state); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1175 | spin_unlock_irqrestore(&brd_lock, flags); |
| 1176 | |
| 1177 | if (wait == 0) |
| 1178 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1179 | |
| 1180 | /* |
| 1181 | * Slave is in action, so now we must wait for the open acknowledgment |
| 1182 | * to come back. |
| 1183 | */ |
| 1184 | rc = 0; |
| 1185 | wait_event_interruptible(portp->raw_wait, |
| 1186 | !test_bit(ST_CLOSING, &portp->state)); |
| 1187 | if (signal_pending(current)) |
| 1188 | rc = -ERESTARTSYS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | |
| 1190 | if ((rc == 0) && (portp->rc != 0)) |
| 1191 | rc = -EIO; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1192 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | } |
| 1194 | |
| 1195 | /*****************************************************************************/ |
| 1196 | |
| 1197 | /* |
| 1198 | * Send a command to the slave and wait for the response. This must |
| 1199 | * have user context (it sleeps). This routine is generic in that it |
| 1200 | * can send any type of command. Its purpose is to wait for that command |
| 1201 | * to complete (as opposed to initiating the command then returning). |
| 1202 | */ |
| 1203 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 1204 | static int stli_cmdwait(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | wait_event_interruptible(portp->raw_wait, |
| 1207 | !test_bit(ST_CMDING, &portp->state)); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1208 | if (signal_pending(current)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1209 | return -ERESTARTSYS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | |
| 1211 | stli_sendcmd(brdp, portp, cmd, arg, size, copyback); |
| 1212 | |
| 1213 | wait_event_interruptible(portp->raw_wait, |
| 1214 | !test_bit(ST_CMDING, &portp->state)); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1215 | if (signal_pending(current)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1216 | return -ERESTARTSYS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1217 | |
| 1218 | if (portp->rc != 0) |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1219 | return -EIO; |
| 1220 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1221 | } |
| 1222 | |
| 1223 | /*****************************************************************************/ |
| 1224 | |
| 1225 | /* |
| 1226 | * Send the termios settings for this port to the slave. This sleeps |
| 1227 | * waiting for the command to complete - so must have user context. |
| 1228 | */ |
| 1229 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 1230 | static int stli_setport(struct stliport *portp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1231 | { |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 1232 | struct stlibrd *brdp; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1233 | asyport_t aport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1234 | |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1235 | if (portp == NULL) |
| 1236 | return -ENODEV; |
| 1237 | if (portp->tty == NULL) |
| 1238 | return -ENODEV; |
Jiri Slaby | 1328d73 | 2006-12-08 02:39:19 -0800 | [diff] [blame] | 1239 | if (portp->brdnr >= stli_nrbrds) |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1240 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1241 | brdp = stli_brds[portp->brdnr]; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1242 | if (brdp == NULL) |
| 1243 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1244 | |
| 1245 | stli_mkasyport(portp, &aport, portp->tty->termios); |
| 1246 | return(stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0)); |
| 1247 | } |
| 1248 | |
| 1249 | /*****************************************************************************/ |
| 1250 | |
| 1251 | /* |
| 1252 | * Possibly need to wait for carrier (DCD signal) to come high. Say |
| 1253 | * maybe because if we are clocal then we don't need to wait... |
| 1254 | */ |
| 1255 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 1256 | static int stli_waitcarrier(struct stlibrd *brdp, struct stliport *portp, struct file *filp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1258 | unsigned long flags; |
| 1259 | int rc, doclocal; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1260 | |
| 1261 | rc = 0; |
| 1262 | doclocal = 0; |
| 1263 | |
| 1264 | if (portp->tty->termios->c_cflag & CLOCAL) |
| 1265 | doclocal++; |
| 1266 | |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1267 | spin_lock_irqsave(&stli_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | portp->openwaitcnt++; |
| 1269 | if (! tty_hung_up_p(filp)) |
| 1270 | portp->refcount--; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1271 | spin_unlock_irqrestore(&stli_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | |
| 1273 | for (;;) { |
| 1274 | stli_mkasysigs(&portp->asig, 1, 1); |
| 1275 | if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS, |
| 1276 | &portp->asig, sizeof(asysigs_t), 0)) < 0) |
| 1277 | break; |
| 1278 | if (tty_hung_up_p(filp) || |
| 1279 | ((portp->flags & ASYNC_INITIALIZED) == 0)) { |
| 1280 | if (portp->flags & ASYNC_HUP_NOTIFY) |
| 1281 | rc = -EBUSY; |
| 1282 | else |
| 1283 | rc = -ERESTARTSYS; |
| 1284 | break; |
| 1285 | } |
| 1286 | if (((portp->flags & ASYNC_CLOSING) == 0) && |
| 1287 | (doclocal || (portp->sigs & TIOCM_CD))) { |
| 1288 | break; |
| 1289 | } |
| 1290 | if (signal_pending(current)) { |
| 1291 | rc = -ERESTARTSYS; |
| 1292 | break; |
| 1293 | } |
| 1294 | interruptible_sleep_on(&portp->open_wait); |
| 1295 | } |
| 1296 | |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1297 | spin_lock_irqsave(&stli_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1298 | if (! tty_hung_up_p(filp)) |
| 1299 | portp->refcount++; |
| 1300 | portp->openwaitcnt--; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1301 | spin_unlock_irqrestore(&stli_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1302 | |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1303 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1304 | } |
| 1305 | |
| 1306 | /*****************************************************************************/ |
| 1307 | |
| 1308 | /* |
| 1309 | * Write routine. Take the data and put it in the shared memory ring |
| 1310 | * queue. If port is not already sending chars then need to mark the |
| 1311 | * service bits for this port. |
| 1312 | */ |
| 1313 | |
| 1314 | static int stli_write(struct tty_struct *tty, const unsigned char *buf, int count) |
| 1315 | { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1316 | cdkasy_t __iomem *ap; |
| 1317 | cdkhdr_t __iomem *hdrp; |
| 1318 | unsigned char __iomem *bits; |
| 1319 | unsigned char __iomem *shbuf; |
| 1320 | unsigned char *chbuf; |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 1321 | struct stliport *portp; |
| 1322 | struct stlibrd *brdp; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1323 | unsigned int len, stlen, head, tail, size; |
| 1324 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1325 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1326 | if (tty == stli_txcooktty) |
| 1327 | stli_flushchars(tty); |
| 1328 | portp = tty->driver_data; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1329 | if (portp == NULL) |
| 1330 | return 0; |
Jiri Slaby | 1328d73 | 2006-12-08 02:39:19 -0800 | [diff] [blame] | 1331 | if (portp->brdnr >= stli_nrbrds) |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1332 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1333 | brdp = stli_brds[portp->brdnr]; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1334 | if (brdp == NULL) |
| 1335 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1336 | chbuf = (unsigned char *) buf; |
| 1337 | |
| 1338 | /* |
| 1339 | * All data is now local, shove as much as possible into shared memory. |
| 1340 | */ |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1341 | spin_lock_irqsave(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | EBRDENABLE(brdp); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1343 | ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr); |
| 1344 | head = (unsigned int) readw(&ap->txq.head); |
| 1345 | tail = (unsigned int) readw(&ap->txq.tail); |
| 1346 | if (tail != ((unsigned int) readw(&ap->txq.tail))) |
| 1347 | tail = (unsigned int) readw(&ap->txq.tail); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1348 | size = portp->txsize; |
| 1349 | if (head >= tail) { |
| 1350 | len = size - (head - tail) - 1; |
| 1351 | stlen = size - head; |
| 1352 | } else { |
| 1353 | len = tail - head - 1; |
| 1354 | stlen = len; |
| 1355 | } |
| 1356 | |
Jiri Slaby | a3f8d9d | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 1357 | len = min(len, (unsigned int)count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1358 | count = 0; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1359 | shbuf = (char __iomem *) EBRDGETMEMPTR(brdp, portp->txoffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | |
| 1361 | while (len > 0) { |
Jiri Slaby | a3f8d9d | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 1362 | stlen = min(len, stlen); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1363 | memcpy_toio(shbuf + head, chbuf, stlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1364 | chbuf += stlen; |
| 1365 | len -= stlen; |
| 1366 | count += stlen; |
| 1367 | head += stlen; |
| 1368 | if (head >= size) { |
| 1369 | head = 0; |
| 1370 | stlen = tail; |
| 1371 | } |
| 1372 | } |
| 1373 | |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1374 | ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr); |
| 1375 | writew(head, &ap->txq.head); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1376 | if (test_bit(ST_TXBUSY, &portp->state)) { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1377 | if (readl(&ap->changed.data) & DT_TXEMPTY) |
| 1378 | writel(readl(&ap->changed.data) & ~DT_TXEMPTY, &ap->changed.data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | } |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1380 | hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR); |
| 1381 | bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1382 | portp->portidx; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1383 | writeb(readb(bits) | portp->portbit, bits); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1384 | set_bit(ST_TXBUSY, &portp->state); |
| 1385 | EBRDDISABLE(brdp); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1386 | spin_unlock_irqrestore(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | |
| 1388 | return(count); |
| 1389 | } |
| 1390 | |
| 1391 | /*****************************************************************************/ |
| 1392 | |
| 1393 | /* |
| 1394 | * Output a single character. We put it into a temporary local buffer |
| 1395 | * (for speed) then write out that buffer when the flushchars routine |
| 1396 | * is called. There is a safety catch here so that if some other port |
| 1397 | * writes chars before the current buffer has been, then we write them |
| 1398 | * first them do the new ports. |
| 1399 | */ |
| 1400 | |
| 1401 | static void stli_putchar(struct tty_struct *tty, unsigned char ch) |
| 1402 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 | if (tty != stli_txcooktty) { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1404 | if (stli_txcooktty != NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1405 | stli_flushchars(stli_txcooktty); |
| 1406 | stli_txcooktty = tty; |
| 1407 | } |
| 1408 | |
| 1409 | stli_txcookbuf[stli_txcooksize++] = ch; |
| 1410 | } |
| 1411 | |
| 1412 | /*****************************************************************************/ |
| 1413 | |
| 1414 | /* |
| 1415 | * Transfer characters from the local TX cooking buffer to the board. |
| 1416 | * We sort of ignore the tty that gets passed in here. We rely on the |
| 1417 | * info stored with the TX cook buffer to tell us which port to flush |
| 1418 | * the data on. In any case we clean out the TX cook buffer, for re-use |
| 1419 | * by someone else. |
| 1420 | */ |
| 1421 | |
| 1422 | static void stli_flushchars(struct tty_struct *tty) |
| 1423 | { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1424 | cdkhdr_t __iomem *hdrp; |
| 1425 | unsigned char __iomem *bits; |
| 1426 | cdkasy_t __iomem *ap; |
| 1427 | struct tty_struct *cooktty; |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 1428 | struct stliport *portp; |
| 1429 | struct stlibrd *brdp; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1430 | unsigned int len, stlen, head, tail, size, count, cooksize; |
| 1431 | unsigned char *buf; |
| 1432 | unsigned char __iomem *shbuf; |
| 1433 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1434 | |
| 1435 | cooksize = stli_txcooksize; |
| 1436 | cooktty = stli_txcooktty; |
| 1437 | stli_txcooksize = 0; |
| 1438 | stli_txcookrealsize = 0; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1439 | stli_txcooktty = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1440 | |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1441 | if (tty == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1442 | return; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1443 | if (cooktty == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1444 | return; |
| 1445 | if (tty != cooktty) |
| 1446 | tty = cooktty; |
| 1447 | if (cooksize == 0) |
| 1448 | return; |
| 1449 | |
| 1450 | portp = tty->driver_data; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1451 | if (portp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1452 | return; |
Jiri Slaby | 1328d73 | 2006-12-08 02:39:19 -0800 | [diff] [blame] | 1453 | if (portp->brdnr >= stli_nrbrds) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1454 | return; |
| 1455 | brdp = stli_brds[portp->brdnr]; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1456 | if (brdp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1457 | return; |
| 1458 | |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1459 | spin_lock_irqsave(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1460 | EBRDENABLE(brdp); |
| 1461 | |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1462 | ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr); |
| 1463 | head = (unsigned int) readw(&ap->txq.head); |
| 1464 | tail = (unsigned int) readw(&ap->txq.tail); |
| 1465 | if (tail != ((unsigned int) readw(&ap->txq.tail))) |
| 1466 | tail = (unsigned int) readw(&ap->txq.tail); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1467 | size = portp->txsize; |
| 1468 | if (head >= tail) { |
| 1469 | len = size - (head - tail) - 1; |
| 1470 | stlen = size - head; |
| 1471 | } else { |
| 1472 | len = tail - head - 1; |
| 1473 | stlen = len; |
| 1474 | } |
| 1475 | |
Jiri Slaby | a3f8d9d | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 1476 | len = min(len, cooksize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1477 | count = 0; |
Al Viro | 29756fa | 2006-10-10 22:47:27 +0100 | [diff] [blame] | 1478 | shbuf = EBRDGETMEMPTR(brdp, portp->txoffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1479 | buf = stli_txcookbuf; |
| 1480 | |
| 1481 | while (len > 0) { |
Jiri Slaby | a3f8d9d | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 1482 | stlen = min(len, stlen); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1483 | memcpy_toio(shbuf + head, buf, stlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1484 | buf += stlen; |
| 1485 | len -= stlen; |
| 1486 | count += stlen; |
| 1487 | head += stlen; |
| 1488 | if (head >= size) { |
| 1489 | head = 0; |
| 1490 | stlen = tail; |
| 1491 | } |
| 1492 | } |
| 1493 | |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1494 | ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr); |
| 1495 | writew(head, &ap->txq.head); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1496 | |
| 1497 | if (test_bit(ST_TXBUSY, &portp->state)) { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1498 | if (readl(&ap->changed.data) & DT_TXEMPTY) |
| 1499 | writel(readl(&ap->changed.data) & ~DT_TXEMPTY, &ap->changed.data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 | } |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1501 | hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR); |
| 1502 | bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1503 | portp->portidx; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1504 | writeb(readb(bits) | portp->portbit, bits); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1505 | set_bit(ST_TXBUSY, &portp->state); |
| 1506 | |
| 1507 | EBRDDISABLE(brdp); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1508 | spin_unlock_irqrestore(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1509 | } |
| 1510 | |
| 1511 | /*****************************************************************************/ |
| 1512 | |
| 1513 | static int stli_writeroom(struct tty_struct *tty) |
| 1514 | { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1515 | cdkasyrq_t __iomem *rp; |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 1516 | struct stliport *portp; |
| 1517 | struct stlibrd *brdp; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1518 | unsigned int head, tail, len; |
| 1519 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1520 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1521 | if (tty == stli_txcooktty) { |
| 1522 | if (stli_txcookrealsize != 0) { |
| 1523 | len = stli_txcookrealsize - stli_txcooksize; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1524 | return len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1525 | } |
| 1526 | } |
| 1527 | |
| 1528 | portp = tty->driver_data; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1529 | if (portp == NULL) |
| 1530 | return 0; |
Jiri Slaby | 1328d73 | 2006-12-08 02:39:19 -0800 | [diff] [blame] | 1531 | if (portp->brdnr >= stli_nrbrds) |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1532 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1533 | brdp = stli_brds[portp->brdnr]; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1534 | if (brdp == NULL) |
| 1535 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1536 | |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1537 | spin_lock_irqsave(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1538 | EBRDENABLE(brdp); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1539 | rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->txq; |
| 1540 | head = (unsigned int) readw(&rp->head); |
| 1541 | tail = (unsigned int) readw(&rp->tail); |
| 1542 | if (tail != ((unsigned int) readw(&rp->tail))) |
| 1543 | tail = (unsigned int) readw(&rp->tail); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1544 | len = (head >= tail) ? (portp->txsize - (head - tail)) : (tail - head); |
| 1545 | len--; |
| 1546 | EBRDDISABLE(brdp); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1547 | spin_unlock_irqrestore(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1548 | |
| 1549 | if (tty == stli_txcooktty) { |
| 1550 | stli_txcookrealsize = len; |
| 1551 | len -= stli_txcooksize; |
| 1552 | } |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1553 | return len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1554 | } |
| 1555 | |
| 1556 | /*****************************************************************************/ |
| 1557 | |
| 1558 | /* |
| 1559 | * Return the number of characters in the transmit buffer. Normally we |
| 1560 | * will return the number of chars in the shared memory ring queue. |
| 1561 | * We need to kludge around the case where the shared memory buffer is |
| 1562 | * empty but not all characters have drained yet, for this case just |
| 1563 | * return that there is 1 character in the buffer! |
| 1564 | */ |
| 1565 | |
| 1566 | static int stli_charsinbuffer(struct tty_struct *tty) |
| 1567 | { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1568 | cdkasyrq_t __iomem *rp; |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 1569 | struct stliport *portp; |
| 1570 | struct stlibrd *brdp; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1571 | unsigned int head, tail, len; |
| 1572 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1573 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1574 | if (tty == stli_txcooktty) |
| 1575 | stli_flushchars(tty); |
| 1576 | portp = tty->driver_data; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1577 | if (portp == NULL) |
| 1578 | return 0; |
Jiri Slaby | 1328d73 | 2006-12-08 02:39:19 -0800 | [diff] [blame] | 1579 | if (portp->brdnr >= stli_nrbrds) |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1580 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1581 | brdp = stli_brds[portp->brdnr]; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1582 | if (brdp == NULL) |
| 1583 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1584 | |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1585 | spin_lock_irqsave(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1586 | EBRDENABLE(brdp); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1587 | rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->txq; |
| 1588 | head = (unsigned int) readw(&rp->head); |
| 1589 | tail = (unsigned int) readw(&rp->tail); |
| 1590 | if (tail != ((unsigned int) readw(&rp->tail))) |
| 1591 | tail = (unsigned int) readw(&rp->tail); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1592 | len = (head >= tail) ? (head - tail) : (portp->txsize - (tail - head)); |
| 1593 | if ((len == 0) && test_bit(ST_TXBUSY, &portp->state)) |
| 1594 | len = 1; |
| 1595 | EBRDDISABLE(brdp); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1596 | spin_unlock_irqrestore(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1597 | |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1598 | return len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1599 | } |
| 1600 | |
| 1601 | /*****************************************************************************/ |
| 1602 | |
| 1603 | /* |
| 1604 | * Generate the serial struct info. |
| 1605 | */ |
| 1606 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 1607 | static int stli_getserial(struct stliport *portp, struct serial_struct __user *sp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1608 | { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1609 | struct serial_struct sio; |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 1610 | struct stlibrd *brdp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1611 | |
| 1612 | memset(&sio, 0, sizeof(struct serial_struct)); |
| 1613 | sio.type = PORT_UNKNOWN; |
| 1614 | sio.line = portp->portnr; |
| 1615 | sio.irq = 0; |
| 1616 | sio.flags = portp->flags; |
| 1617 | sio.baud_base = portp->baud_base; |
| 1618 | sio.close_delay = portp->close_delay; |
| 1619 | sio.closing_wait = portp->closing_wait; |
| 1620 | sio.custom_divisor = portp->custom_divisor; |
| 1621 | sio.xmit_fifo_size = 0; |
| 1622 | sio.hub6 = 0; |
| 1623 | |
| 1624 | brdp = stli_brds[portp->brdnr]; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1625 | if (brdp != NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1626 | sio.port = brdp->iobase; |
| 1627 | |
| 1628 | return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ? |
| 1629 | -EFAULT : 0; |
| 1630 | } |
| 1631 | |
| 1632 | /*****************************************************************************/ |
| 1633 | |
| 1634 | /* |
| 1635 | * Set port according to the serial struct info. |
| 1636 | * At this point we do not do any auto-configure stuff, so we will |
| 1637 | * just quietly ignore any requests to change irq, etc. |
| 1638 | */ |
| 1639 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 1640 | static int stli_setserial(struct stliport *portp, struct serial_struct __user *sp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1641 | { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1642 | struct serial_struct sio; |
| 1643 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1644 | |
| 1645 | if (copy_from_user(&sio, sp, sizeof(struct serial_struct))) |
| 1646 | return -EFAULT; |
| 1647 | if (!capable(CAP_SYS_ADMIN)) { |
| 1648 | if ((sio.baud_base != portp->baud_base) || |
| 1649 | (sio.close_delay != portp->close_delay) || |
| 1650 | ((sio.flags & ~ASYNC_USR_MASK) != |
| 1651 | (portp->flags & ~ASYNC_USR_MASK))) |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1652 | return -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1653 | } |
| 1654 | |
| 1655 | portp->flags = (portp->flags & ~ASYNC_USR_MASK) | |
| 1656 | (sio.flags & ASYNC_USR_MASK); |
| 1657 | portp->baud_base = sio.baud_base; |
| 1658 | portp->close_delay = sio.close_delay; |
| 1659 | portp->closing_wait = sio.closing_wait; |
| 1660 | portp->custom_divisor = sio.custom_divisor; |
| 1661 | |
| 1662 | if ((rc = stli_setport(portp)) < 0) |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1663 | return rc; |
| 1664 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1665 | } |
| 1666 | |
| 1667 | /*****************************************************************************/ |
| 1668 | |
| 1669 | static int stli_tiocmget(struct tty_struct *tty, struct file *file) |
| 1670 | { |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 1671 | struct stliport *portp = tty->driver_data; |
| 1672 | struct stlibrd *brdp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1673 | int rc; |
| 1674 | |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1675 | if (portp == NULL) |
| 1676 | return -ENODEV; |
Jiri Slaby | 1328d73 | 2006-12-08 02:39:19 -0800 | [diff] [blame] | 1677 | if (portp->brdnr >= stli_nrbrds) |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1678 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1679 | brdp = stli_brds[portp->brdnr]; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1680 | if (brdp == NULL) |
| 1681 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1682 | if (tty->flags & (1 << TTY_IO_ERROR)) |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1683 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1684 | |
| 1685 | if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS, |
| 1686 | &portp->asig, sizeof(asysigs_t), 1)) < 0) |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1687 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1688 | |
| 1689 | return stli_mktiocm(portp->asig.sigvalue); |
| 1690 | } |
| 1691 | |
| 1692 | static int stli_tiocmset(struct tty_struct *tty, struct file *file, |
| 1693 | unsigned int set, unsigned int clear) |
| 1694 | { |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 1695 | struct stliport *portp = tty->driver_data; |
| 1696 | struct stlibrd *brdp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1697 | int rts = -1, dtr = -1; |
| 1698 | |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1699 | if (portp == NULL) |
| 1700 | return -ENODEV; |
Jiri Slaby | 1328d73 | 2006-12-08 02:39:19 -0800 | [diff] [blame] | 1701 | if (portp->brdnr >= stli_nrbrds) |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1702 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1703 | brdp = stli_brds[portp->brdnr]; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1704 | if (brdp == NULL) |
| 1705 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1706 | if (tty->flags & (1 << TTY_IO_ERROR)) |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1707 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1708 | |
| 1709 | if (set & TIOCM_RTS) |
| 1710 | rts = 1; |
| 1711 | if (set & TIOCM_DTR) |
| 1712 | dtr = 1; |
| 1713 | if (clear & TIOCM_RTS) |
| 1714 | rts = 0; |
| 1715 | if (clear & TIOCM_DTR) |
| 1716 | dtr = 0; |
| 1717 | |
| 1718 | stli_mkasysigs(&portp->asig, dtr, rts); |
| 1719 | |
| 1720 | return stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig, |
| 1721 | sizeof(asysigs_t), 0); |
| 1722 | } |
| 1723 | |
| 1724 | static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg) |
| 1725 | { |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 1726 | struct stliport *portp; |
| 1727 | struct stlibrd *brdp; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1728 | unsigned int ival; |
| 1729 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1730 | void __user *argp = (void __user *)arg; |
| 1731 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1732 | portp = tty->driver_data; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1733 | if (portp == NULL) |
| 1734 | return -ENODEV; |
Jiri Slaby | 1328d73 | 2006-12-08 02:39:19 -0800 | [diff] [blame] | 1735 | if (portp->brdnr >= stli_nrbrds) |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1736 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1737 | brdp = stli_brds[portp->brdnr]; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1738 | if (brdp == NULL) |
| 1739 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1740 | |
| 1741 | if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) && |
| 1742 | (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) { |
| 1743 | if (tty->flags & (1 << TTY_IO_ERROR)) |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1744 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1745 | } |
| 1746 | |
| 1747 | rc = 0; |
| 1748 | |
| 1749 | switch (cmd) { |
| 1750 | case TIOCGSOFTCAR: |
| 1751 | rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0), |
| 1752 | (unsigned __user *) arg); |
| 1753 | break; |
| 1754 | case TIOCSSOFTCAR: |
| 1755 | if ((rc = get_user(ival, (unsigned __user *) arg)) == 0) |
| 1756 | tty->termios->c_cflag = |
| 1757 | (tty->termios->c_cflag & ~CLOCAL) | |
| 1758 | (ival ? CLOCAL : 0); |
| 1759 | break; |
| 1760 | case TIOCGSERIAL: |
| 1761 | rc = stli_getserial(portp, argp); |
| 1762 | break; |
| 1763 | case TIOCSSERIAL: |
| 1764 | rc = stli_setserial(portp, argp); |
| 1765 | break; |
| 1766 | case STL_GETPFLAG: |
| 1767 | rc = put_user(portp->pflag, (unsigned __user *)argp); |
| 1768 | break; |
| 1769 | case STL_SETPFLAG: |
| 1770 | if ((rc = get_user(portp->pflag, (unsigned __user *)argp)) == 0) |
| 1771 | stli_setport(portp); |
| 1772 | break; |
| 1773 | case COM_GETPORTSTATS: |
| 1774 | rc = stli_getportstats(portp, argp); |
| 1775 | break; |
| 1776 | case COM_CLRPORTSTATS: |
| 1777 | rc = stli_clrportstats(portp, argp); |
| 1778 | break; |
| 1779 | case TIOCSERCONFIG: |
| 1780 | case TIOCSERGWILD: |
| 1781 | case TIOCSERSWILD: |
| 1782 | case TIOCSERGETLSR: |
| 1783 | case TIOCSERGSTRUCT: |
| 1784 | case TIOCSERGETMULTI: |
| 1785 | case TIOCSERSETMULTI: |
| 1786 | default: |
| 1787 | rc = -ENOIOCTLCMD; |
| 1788 | break; |
| 1789 | } |
| 1790 | |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1791 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1792 | } |
| 1793 | |
| 1794 | /*****************************************************************************/ |
| 1795 | |
| 1796 | /* |
| 1797 | * This routine assumes that we have user context and can sleep. |
| 1798 | * Looks like it is true for the current ttys implementation..!! |
| 1799 | */ |
| 1800 | |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 1801 | static void stli_settermios(struct tty_struct *tty, struct ktermios *old) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1802 | { |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 1803 | struct stliport *portp; |
| 1804 | struct stlibrd *brdp; |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 1805 | struct ktermios *tiosp; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1806 | asyport_t aport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1807 | |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1808 | if (tty == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1809 | return; |
| 1810 | portp = tty->driver_data; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1811 | if (portp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1812 | return; |
Jiri Slaby | 1328d73 | 2006-12-08 02:39:19 -0800 | [diff] [blame] | 1813 | if (portp->brdnr >= stli_nrbrds) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1814 | return; |
| 1815 | brdp = stli_brds[portp->brdnr]; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1816 | if (brdp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1817 | return; |
| 1818 | |
| 1819 | tiosp = tty->termios; |
| 1820 | if ((tiosp->c_cflag == old->c_cflag) && |
| 1821 | (tiosp->c_iflag == old->c_iflag)) |
| 1822 | return; |
| 1823 | |
| 1824 | stli_mkasyport(portp, &aport, tiosp); |
| 1825 | stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0); |
| 1826 | stli_mkasysigs(&portp->asig, ((tiosp->c_cflag & CBAUD) ? 1 : 0), -1); |
| 1827 | stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig, |
| 1828 | sizeof(asysigs_t), 0); |
| 1829 | if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0)) |
| 1830 | tty->hw_stopped = 0; |
| 1831 | if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL)) |
| 1832 | wake_up_interruptible(&portp->open_wait); |
| 1833 | } |
| 1834 | |
| 1835 | /*****************************************************************************/ |
| 1836 | |
| 1837 | /* |
| 1838 | * Attempt to flow control who ever is sending us data. We won't really |
| 1839 | * do any flow control action here. We can't directly, and even if we |
| 1840 | * wanted to we would have to send a command to the slave. The slave |
| 1841 | * knows how to flow control, and will do so when its buffers reach its |
| 1842 | * internal high water marks. So what we will do is set a local state |
| 1843 | * bit that will stop us sending any RX data up from the poll routine |
| 1844 | * (which is the place where RX data from the slave is handled). |
| 1845 | */ |
| 1846 | |
| 1847 | static void stli_throttle(struct tty_struct *tty) |
| 1848 | { |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 1849 | struct stliport *portp = tty->driver_data; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1850 | if (portp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1851 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1852 | set_bit(ST_RXSTOP, &portp->state); |
| 1853 | } |
| 1854 | |
| 1855 | /*****************************************************************************/ |
| 1856 | |
| 1857 | /* |
| 1858 | * Unflow control the device sending us data... That means that all |
| 1859 | * we have to do is clear the RXSTOP state bit. The next poll call |
| 1860 | * will then be able to pass the RX data back up. |
| 1861 | */ |
| 1862 | |
| 1863 | static void stli_unthrottle(struct tty_struct *tty) |
| 1864 | { |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 1865 | struct stliport *portp = tty->driver_data; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1866 | if (portp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1867 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1868 | clear_bit(ST_RXSTOP, &portp->state); |
| 1869 | } |
| 1870 | |
| 1871 | /*****************************************************************************/ |
| 1872 | |
| 1873 | /* |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1874 | * Stop the transmitter. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1875 | */ |
| 1876 | |
| 1877 | static void stli_stop(struct tty_struct *tty) |
| 1878 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | } |
| 1880 | |
| 1881 | /*****************************************************************************/ |
| 1882 | |
| 1883 | /* |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1884 | * Start the transmitter again. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1885 | */ |
| 1886 | |
| 1887 | static void stli_start(struct tty_struct *tty) |
| 1888 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1889 | } |
| 1890 | |
| 1891 | /*****************************************************************************/ |
| 1892 | |
| 1893 | /* |
| 1894 | * Scheduler called hang up routine. This is called from the scheduler, |
| 1895 | * not direct from the driver "poll" routine. We can't call it there |
| 1896 | * since the real local hangup code will enable/disable the board and |
| 1897 | * other things that we can't do while handling the poll. Much easier |
| 1898 | * to deal with it some time later (don't really care when, hangups |
| 1899 | * aren't that time critical). |
| 1900 | */ |
| 1901 | |
Al Viro | 3e577a8 | 2006-12-06 18:41:45 +0000 | [diff] [blame] | 1902 | static void stli_dohangup(struct work_struct *ugly_api) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1903 | { |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 1904 | struct stliport *portp = container_of(ugly_api, struct stliport, tqhangup); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1905 | if (portp->tty != NULL) { |
| 1906 | tty_hangup(portp->tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1907 | } |
| 1908 | } |
| 1909 | |
| 1910 | /*****************************************************************************/ |
| 1911 | |
| 1912 | /* |
| 1913 | * Hangup this port. This is pretty much like closing the port, only |
| 1914 | * a little more brutal. No waiting for data to drain. Shutdown the |
| 1915 | * port and maybe drop signals. This is rather tricky really. We want |
| 1916 | * to close the port as well. |
| 1917 | */ |
| 1918 | |
| 1919 | static void stli_hangup(struct tty_struct *tty) |
| 1920 | { |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 1921 | struct stliport *portp; |
| 1922 | struct stlibrd *brdp; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1923 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1924 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1925 | portp = tty->driver_data; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1926 | if (portp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1927 | return; |
Jiri Slaby | 1328d73 | 2006-12-08 02:39:19 -0800 | [diff] [blame] | 1928 | if (portp->brdnr >= stli_nrbrds) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1929 | return; |
| 1930 | brdp = stli_brds[portp->brdnr]; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1931 | if (brdp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1932 | return; |
| 1933 | |
| 1934 | portp->flags &= ~ASYNC_INITIALIZED; |
| 1935 | |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1936 | if (!test_bit(ST_CLOSING, &portp->state)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1937 | stli_rawclose(brdp, portp, 0, 0); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1938 | |
| 1939 | spin_lock_irqsave(&stli_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1940 | if (tty->termios->c_cflag & HUPCL) { |
| 1941 | stli_mkasysigs(&portp->asig, 0, 0); |
| 1942 | if (test_bit(ST_CMDING, &portp->state)) { |
| 1943 | set_bit(ST_DOSIGS, &portp->state); |
| 1944 | set_bit(ST_DOFLUSHTX, &portp->state); |
| 1945 | set_bit(ST_DOFLUSHRX, &portp->state); |
| 1946 | } else { |
| 1947 | stli_sendcmd(brdp, portp, A_SETSIGNALSF, |
| 1948 | &portp->asig, sizeof(asysigs_t), 0); |
| 1949 | } |
| 1950 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1951 | |
| 1952 | clear_bit(ST_TXBUSY, &portp->state); |
| 1953 | clear_bit(ST_RXSTOP, &portp->state); |
| 1954 | set_bit(TTY_IO_ERROR, &tty->flags); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1955 | portp->tty = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1956 | portp->flags &= ~ASYNC_NORMAL_ACTIVE; |
| 1957 | portp->refcount = 0; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1958 | spin_unlock_irqrestore(&stli_lock, flags); |
| 1959 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1960 | wake_up_interruptible(&portp->open_wait); |
| 1961 | } |
| 1962 | |
| 1963 | /*****************************************************************************/ |
| 1964 | |
| 1965 | /* |
| 1966 | * Flush characters from the lower buffer. We may not have user context |
| 1967 | * so we cannot sleep waiting for it to complete. Also we need to check |
| 1968 | * if there is chars for this port in the TX cook buffer, and flush them |
| 1969 | * as well. |
| 1970 | */ |
| 1971 | |
| 1972 | static void stli_flushbuffer(struct tty_struct *tty) |
| 1973 | { |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 1974 | struct stliport *portp; |
| 1975 | struct stlibrd *brdp; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1976 | unsigned long ftype, flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1977 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1978 | portp = tty->driver_data; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1979 | if (portp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1980 | return; |
Jiri Slaby | 1328d73 | 2006-12-08 02:39:19 -0800 | [diff] [blame] | 1981 | if (portp->brdnr >= stli_nrbrds) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1982 | return; |
| 1983 | brdp = stli_brds[portp->brdnr]; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1984 | if (brdp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1985 | return; |
| 1986 | |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1987 | spin_lock_irqsave(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1988 | if (tty == stli_txcooktty) { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 1989 | stli_txcooktty = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1990 | stli_txcooksize = 0; |
| 1991 | stli_txcookrealsize = 0; |
| 1992 | } |
| 1993 | if (test_bit(ST_CMDING, &portp->state)) { |
| 1994 | set_bit(ST_DOFLUSHTX, &portp->state); |
| 1995 | } else { |
| 1996 | ftype = FLUSHTX; |
| 1997 | if (test_bit(ST_DOFLUSHRX, &portp->state)) { |
| 1998 | ftype |= FLUSHRX; |
| 1999 | clear_bit(ST_DOFLUSHRX, &portp->state); |
| 2000 | } |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2001 | __stli_sendcmd(brdp, portp, A_FLUSH, &ftype, sizeof(u32), 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2002 | } |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2003 | spin_unlock_irqrestore(&brd_lock, flags); |
| 2004 | tty_wakeup(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2005 | } |
| 2006 | |
| 2007 | /*****************************************************************************/ |
| 2008 | |
| 2009 | static void stli_breakctl(struct tty_struct *tty, int state) |
| 2010 | { |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 2011 | struct stlibrd *brdp; |
| 2012 | struct stliport *portp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2013 | long arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2014 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2015 | portp = tty->driver_data; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2016 | if (portp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2017 | return; |
Jiri Slaby | 1328d73 | 2006-12-08 02:39:19 -0800 | [diff] [blame] | 2018 | if (portp->brdnr >= stli_nrbrds) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2019 | return; |
| 2020 | brdp = stli_brds[portp->brdnr]; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2021 | if (brdp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2022 | return; |
| 2023 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2024 | arg = (state == -1) ? BREAKON : BREAKOFF; |
| 2025 | stli_cmdwait(brdp, portp, A_BREAK, &arg, sizeof(long), 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2026 | } |
| 2027 | |
| 2028 | /*****************************************************************************/ |
| 2029 | |
| 2030 | static void stli_waituntilsent(struct tty_struct *tty, int timeout) |
| 2031 | { |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 2032 | struct stliport *portp; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2033 | unsigned long tend; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2034 | |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2035 | if (tty == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2036 | return; |
| 2037 | portp = tty->driver_data; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2038 | if (portp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2039 | return; |
| 2040 | |
| 2041 | if (timeout == 0) |
| 2042 | timeout = HZ; |
| 2043 | tend = jiffies + timeout; |
| 2044 | |
| 2045 | while (test_bit(ST_TXBUSY, &portp->state)) { |
| 2046 | if (signal_pending(current)) |
| 2047 | break; |
| 2048 | msleep_interruptible(20); |
| 2049 | if (time_after_eq(jiffies, tend)) |
| 2050 | break; |
| 2051 | } |
| 2052 | } |
| 2053 | |
| 2054 | /*****************************************************************************/ |
| 2055 | |
| 2056 | static void stli_sendxchar(struct tty_struct *tty, char ch) |
| 2057 | { |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 2058 | struct stlibrd *brdp; |
| 2059 | struct stliport *portp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2060 | asyctrl_t actrl; |
| 2061 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2062 | portp = tty->driver_data; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2063 | if (portp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2064 | return; |
Jiri Slaby | 1328d73 | 2006-12-08 02:39:19 -0800 | [diff] [blame] | 2065 | if (portp->brdnr >= stli_nrbrds) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2066 | return; |
| 2067 | brdp = stli_brds[portp->brdnr]; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2068 | if (brdp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2069 | return; |
| 2070 | |
| 2071 | memset(&actrl, 0, sizeof(asyctrl_t)); |
| 2072 | if (ch == STOP_CHAR(tty)) { |
| 2073 | actrl.rxctrl = CT_STOPFLOW; |
| 2074 | } else if (ch == START_CHAR(tty)) { |
| 2075 | actrl.rxctrl = CT_STARTFLOW; |
| 2076 | } else { |
| 2077 | actrl.txctrl = CT_SENDCHR; |
| 2078 | actrl.tximdch = ch; |
| 2079 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2080 | stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0); |
| 2081 | } |
| 2082 | |
| 2083 | /*****************************************************************************/ |
| 2084 | |
| 2085 | #define MAXLINE 80 |
| 2086 | |
| 2087 | /* |
| 2088 | * Format info for a specified port. The line is deliberately limited |
| 2089 | * to 80 characters. (If it is too long it will be truncated, if too |
| 2090 | * short then padded with spaces). |
| 2091 | */ |
| 2092 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 2093 | static int stli_portinfo(struct stlibrd *brdp, struct stliport *portp, int portnr, char *pos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2094 | { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2095 | char *sp, *uart; |
| 2096 | int rc, cnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2097 | |
| 2098 | rc = stli_portcmdstats(portp); |
| 2099 | |
| 2100 | uart = "UNKNOWN"; |
| 2101 | if (brdp->state & BST_STARTED) { |
| 2102 | switch (stli_comstats.hwid) { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2103 | case 0: uart = "2681"; break; |
| 2104 | case 1: uart = "SC26198"; break; |
| 2105 | default:uart = "CD1400"; break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2106 | } |
| 2107 | } |
| 2108 | |
| 2109 | sp = pos; |
| 2110 | sp += sprintf(sp, "%d: uart:%s ", portnr, uart); |
| 2111 | |
| 2112 | if ((brdp->state & BST_STARTED) && (rc >= 0)) { |
| 2113 | sp += sprintf(sp, "tx:%d rx:%d", (int) stli_comstats.txtotal, |
| 2114 | (int) stli_comstats.rxtotal); |
| 2115 | |
| 2116 | if (stli_comstats.rxframing) |
| 2117 | sp += sprintf(sp, " fe:%d", |
| 2118 | (int) stli_comstats.rxframing); |
| 2119 | if (stli_comstats.rxparity) |
| 2120 | sp += sprintf(sp, " pe:%d", |
| 2121 | (int) stli_comstats.rxparity); |
| 2122 | if (stli_comstats.rxbreaks) |
| 2123 | sp += sprintf(sp, " brk:%d", |
| 2124 | (int) stli_comstats.rxbreaks); |
| 2125 | if (stli_comstats.rxoverrun) |
| 2126 | sp += sprintf(sp, " oe:%d", |
| 2127 | (int) stli_comstats.rxoverrun); |
| 2128 | |
| 2129 | cnt = sprintf(sp, "%s%s%s%s%s ", |
| 2130 | (stli_comstats.signals & TIOCM_RTS) ? "|RTS" : "", |
| 2131 | (stli_comstats.signals & TIOCM_CTS) ? "|CTS" : "", |
| 2132 | (stli_comstats.signals & TIOCM_DTR) ? "|DTR" : "", |
| 2133 | (stli_comstats.signals & TIOCM_CD) ? "|DCD" : "", |
| 2134 | (stli_comstats.signals & TIOCM_DSR) ? "|DSR" : ""); |
| 2135 | *sp = ' '; |
| 2136 | sp += cnt; |
| 2137 | } |
| 2138 | |
| 2139 | for (cnt = (sp - pos); (cnt < (MAXLINE - 1)); cnt++) |
| 2140 | *sp++ = ' '; |
| 2141 | if (cnt >= MAXLINE) |
| 2142 | pos[(MAXLINE - 2)] = '+'; |
| 2143 | pos[(MAXLINE - 1)] = '\n'; |
| 2144 | |
| 2145 | return(MAXLINE); |
| 2146 | } |
| 2147 | |
| 2148 | /*****************************************************************************/ |
| 2149 | |
| 2150 | /* |
| 2151 | * Port info, read from the /proc file system. |
| 2152 | */ |
| 2153 | |
| 2154 | static int stli_readproc(char *page, char **start, off_t off, int count, int *eof, void *data) |
| 2155 | { |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 2156 | struct stlibrd *brdp; |
| 2157 | struct stliport *portp; |
Jiri Slaby | 1328d73 | 2006-12-08 02:39:19 -0800 | [diff] [blame] | 2158 | unsigned int brdnr, portnr, totalport; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2159 | int curoff, maxoff; |
| 2160 | char *pos; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2161 | |
| 2162 | pos = page; |
| 2163 | totalport = 0; |
| 2164 | curoff = 0; |
| 2165 | |
| 2166 | if (off == 0) { |
| 2167 | pos += sprintf(pos, "%s: version %s", stli_drvtitle, |
| 2168 | stli_drvversion); |
| 2169 | while (pos < (page + MAXLINE - 1)) |
| 2170 | *pos++ = ' '; |
| 2171 | *pos++ = '\n'; |
| 2172 | } |
| 2173 | curoff = MAXLINE; |
| 2174 | |
| 2175 | /* |
| 2176 | * We scan through for each board, panel and port. The offset is |
| 2177 | * calculated on the fly, and irrelevant ports are skipped. |
| 2178 | */ |
| 2179 | for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) { |
| 2180 | brdp = stli_brds[brdnr]; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2181 | if (brdp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2182 | continue; |
| 2183 | if (brdp->state == 0) |
| 2184 | continue; |
| 2185 | |
| 2186 | maxoff = curoff + (brdp->nrports * MAXLINE); |
| 2187 | if (off >= maxoff) { |
| 2188 | curoff = maxoff; |
| 2189 | continue; |
| 2190 | } |
| 2191 | |
| 2192 | totalport = brdnr * STL_MAXPORTS; |
| 2193 | for (portnr = 0; (portnr < brdp->nrports); portnr++, |
| 2194 | totalport++) { |
| 2195 | portp = brdp->ports[portnr]; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2196 | if (portp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2197 | continue; |
| 2198 | if (off >= (curoff += MAXLINE)) |
| 2199 | continue; |
| 2200 | if ((pos - page + MAXLINE) > count) |
| 2201 | goto stli_readdone; |
| 2202 | pos += stli_portinfo(brdp, portp, totalport, pos); |
| 2203 | } |
| 2204 | } |
| 2205 | |
| 2206 | *eof = 1; |
| 2207 | |
| 2208 | stli_readdone: |
| 2209 | *start = page; |
| 2210 | return(pos - page); |
| 2211 | } |
| 2212 | |
| 2213 | /*****************************************************************************/ |
| 2214 | |
| 2215 | /* |
| 2216 | * Generic send command routine. This will send a message to the slave, |
| 2217 | * of the specified type with the specified argument. Must be very |
| 2218 | * careful of data that will be copied out from shared memory - |
| 2219 | * containing command results. The command completion is all done from |
| 2220 | * a poll routine that does not have user context. Therefore you cannot |
| 2221 | * copy back directly into user space, or to the kernel stack of a |
| 2222 | * process. This routine does not sleep, so can be called from anywhere. |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2223 | * |
| 2224 | * The caller must hold the brd_lock (see also stli_sendcmd the usual |
| 2225 | * entry point) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2226 | */ |
| 2227 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 2228 | static void __stli_sendcmd(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2229 | { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2230 | cdkhdr_t __iomem *hdrp; |
| 2231 | cdkctrl_t __iomem *cp; |
| 2232 | unsigned char __iomem *bits; |
| 2233 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2234 | |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2235 | spin_lock_irqsave(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2236 | |
| 2237 | if (test_bit(ST_CMDING, &portp->state)) { |
| 2238 | printk(KERN_ERR "STALLION: command already busy, cmd=%x!\n", |
| 2239 | (int) cmd); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2240 | spin_unlock_irqrestore(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2241 | return; |
| 2242 | } |
| 2243 | |
| 2244 | EBRDENABLE(brdp); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2245 | cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2246 | if (size > 0) { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2247 | memcpy_toio((void __iomem *) &(cp->args[0]), arg, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2248 | if (copyback) { |
| 2249 | portp->argp = arg; |
| 2250 | portp->argsize = size; |
| 2251 | } |
| 2252 | } |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2253 | writel(0, &cp->status); |
| 2254 | writel(cmd, &cp->cmd); |
| 2255 | hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR); |
| 2256 | bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2257 | portp->portidx; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2258 | writeb(readb(bits) | portp->portbit, bits); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2259 | set_bit(ST_CMDING, &portp->state); |
| 2260 | EBRDDISABLE(brdp); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2261 | spin_unlock_irqrestore(&brd_lock, flags); |
| 2262 | } |
| 2263 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 2264 | static void stli_sendcmd(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback) |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2265 | { |
| 2266 | unsigned long flags; |
| 2267 | |
| 2268 | spin_lock_irqsave(&brd_lock, flags); |
| 2269 | __stli_sendcmd(brdp, portp, cmd, arg, size, copyback); |
| 2270 | spin_unlock_irqrestore(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2271 | } |
| 2272 | |
| 2273 | /*****************************************************************************/ |
| 2274 | |
| 2275 | /* |
| 2276 | * Read data from shared memory. This assumes that the shared memory |
| 2277 | * is enabled and that interrupts are off. Basically we just empty out |
| 2278 | * the shared memory buffer into the tty buffer. Must be careful to |
| 2279 | * handle the case where we fill up the tty buffer, but still have |
| 2280 | * more chars to unload. |
| 2281 | */ |
| 2282 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 2283 | static void stli_read(struct stlibrd *brdp, struct stliport *portp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2284 | { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2285 | cdkasyrq_t __iomem *rp; |
| 2286 | char __iomem *shbuf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2287 | struct tty_struct *tty; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2288 | unsigned int head, tail, size; |
| 2289 | unsigned int len, stlen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2290 | |
| 2291 | if (test_bit(ST_RXSTOP, &portp->state)) |
| 2292 | return; |
| 2293 | tty = portp->tty; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2294 | if (tty == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2295 | return; |
| 2296 | |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2297 | rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->rxq; |
| 2298 | head = (unsigned int) readw(&rp->head); |
| 2299 | if (head != ((unsigned int) readw(&rp->head))) |
| 2300 | head = (unsigned int) readw(&rp->head); |
| 2301 | tail = (unsigned int) readw(&rp->tail); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2302 | size = portp->rxsize; |
| 2303 | if (head >= tail) { |
| 2304 | len = head - tail; |
| 2305 | stlen = len; |
| 2306 | } else { |
| 2307 | len = size - (tail - head); |
| 2308 | stlen = size - tail; |
| 2309 | } |
| 2310 | |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 2311 | len = tty_buffer_request_room(tty, len); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2312 | |
| 2313 | shbuf = (char __iomem *) EBRDGETMEMPTR(brdp, portp->rxoffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2314 | |
| 2315 | while (len > 0) { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2316 | unsigned char *cptr; |
| 2317 | |
Jiri Slaby | a3f8d9d | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 2318 | stlen = min(len, stlen); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2319 | tty_prepare_flip_string(tty, &cptr, stlen); |
| 2320 | memcpy_fromio(cptr, shbuf + tail, stlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2321 | len -= stlen; |
| 2322 | tail += stlen; |
| 2323 | if (tail >= size) { |
| 2324 | tail = 0; |
| 2325 | stlen = head; |
| 2326 | } |
| 2327 | } |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2328 | rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->rxq; |
| 2329 | writew(tail, &rp->tail); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2330 | |
| 2331 | if (head != tail) |
| 2332 | set_bit(ST_RXING, &portp->state); |
| 2333 | |
| 2334 | tty_schedule_flip(tty); |
| 2335 | } |
| 2336 | |
| 2337 | /*****************************************************************************/ |
| 2338 | |
| 2339 | /* |
| 2340 | * Set up and carry out any delayed commands. There is only a small set |
| 2341 | * of slave commands that can be done "off-level". So it is not too |
| 2342 | * difficult to deal with them here. |
| 2343 | */ |
| 2344 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 2345 | static void stli_dodelaycmd(struct stliport *portp, cdkctrl_t __iomem *cp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2346 | { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2347 | int cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2348 | |
| 2349 | if (test_bit(ST_DOSIGS, &portp->state)) { |
| 2350 | if (test_bit(ST_DOFLUSHTX, &portp->state) && |
| 2351 | test_bit(ST_DOFLUSHRX, &portp->state)) |
| 2352 | cmd = A_SETSIGNALSF; |
| 2353 | else if (test_bit(ST_DOFLUSHTX, &portp->state)) |
| 2354 | cmd = A_SETSIGNALSFTX; |
| 2355 | else if (test_bit(ST_DOFLUSHRX, &portp->state)) |
| 2356 | cmd = A_SETSIGNALSFRX; |
| 2357 | else |
| 2358 | cmd = A_SETSIGNALS; |
| 2359 | clear_bit(ST_DOFLUSHTX, &portp->state); |
| 2360 | clear_bit(ST_DOFLUSHRX, &portp->state); |
| 2361 | clear_bit(ST_DOSIGS, &portp->state); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2362 | memcpy_toio((void __iomem *) &(cp->args[0]), (void *) &portp->asig, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2363 | sizeof(asysigs_t)); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2364 | writel(0, &cp->status); |
| 2365 | writel(cmd, &cp->cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2366 | set_bit(ST_CMDING, &portp->state); |
| 2367 | } else if (test_bit(ST_DOFLUSHTX, &portp->state) || |
| 2368 | test_bit(ST_DOFLUSHRX, &portp->state)) { |
| 2369 | cmd = ((test_bit(ST_DOFLUSHTX, &portp->state)) ? FLUSHTX : 0); |
| 2370 | cmd |= ((test_bit(ST_DOFLUSHRX, &portp->state)) ? FLUSHRX : 0); |
| 2371 | clear_bit(ST_DOFLUSHTX, &portp->state); |
| 2372 | clear_bit(ST_DOFLUSHRX, &portp->state); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2373 | memcpy_toio((void __iomem *) &(cp->args[0]), (void *) &cmd, sizeof(int)); |
| 2374 | writel(0, &cp->status); |
| 2375 | writel(A_FLUSH, &cp->cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2376 | set_bit(ST_CMDING, &portp->state); |
| 2377 | } |
| 2378 | } |
| 2379 | |
| 2380 | /*****************************************************************************/ |
| 2381 | |
| 2382 | /* |
| 2383 | * Host command service checking. This handles commands or messages |
| 2384 | * coming from the slave to the host. Must have board shared memory |
| 2385 | * enabled and interrupts off when called. Notice that by servicing the |
| 2386 | * read data last we don't need to change the shared memory pointer |
| 2387 | * during processing (which is a slow IO operation). |
| 2388 | * Return value indicates if this port is still awaiting actions from |
| 2389 | * the slave (like open, command, or even TX data being sent). If 0 |
| 2390 | * then port is still busy, otherwise no longer busy. |
| 2391 | */ |
| 2392 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 2393 | static int stli_hostcmd(struct stlibrd *brdp, struct stliport *portp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2394 | { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2395 | cdkasy_t __iomem *ap; |
| 2396 | cdkctrl_t __iomem *cp; |
| 2397 | struct tty_struct *tty; |
| 2398 | asynotify_t nt; |
| 2399 | unsigned long oldsigs; |
| 2400 | int rc, donerx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2401 | |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2402 | ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2403 | cp = &ap->ctrl; |
| 2404 | |
| 2405 | /* |
| 2406 | * Check if we are waiting for an open completion message. |
| 2407 | */ |
| 2408 | if (test_bit(ST_OPENING, &portp->state)) { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2409 | rc = readl(&cp->openarg); |
| 2410 | if (readb(&cp->open) == 0 && rc != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2411 | if (rc > 0) |
| 2412 | rc--; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2413 | writel(0, &cp->openarg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2414 | portp->rc = rc; |
| 2415 | clear_bit(ST_OPENING, &portp->state); |
| 2416 | wake_up_interruptible(&portp->raw_wait); |
| 2417 | } |
| 2418 | } |
| 2419 | |
| 2420 | /* |
| 2421 | * Check if we are waiting for a close completion message. |
| 2422 | */ |
| 2423 | if (test_bit(ST_CLOSING, &portp->state)) { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2424 | rc = (int) readl(&cp->closearg); |
| 2425 | if (readb(&cp->close) == 0 && rc != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2426 | if (rc > 0) |
| 2427 | rc--; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2428 | writel(0, &cp->closearg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2429 | portp->rc = rc; |
| 2430 | clear_bit(ST_CLOSING, &portp->state); |
| 2431 | wake_up_interruptible(&portp->raw_wait); |
| 2432 | } |
| 2433 | } |
| 2434 | |
| 2435 | /* |
| 2436 | * Check if we are waiting for a command completion message. We may |
| 2437 | * need to copy out the command results associated with this command. |
| 2438 | */ |
| 2439 | if (test_bit(ST_CMDING, &portp->state)) { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2440 | rc = readl(&cp->status); |
| 2441 | if (readl(&cp->cmd) == 0 && rc != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2442 | if (rc > 0) |
| 2443 | rc--; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2444 | if (portp->argp != NULL) { |
| 2445 | memcpy_fromio(portp->argp, (void __iomem *) &(cp->args[0]), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2446 | portp->argsize); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2447 | portp->argp = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2448 | } |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2449 | writel(0, &cp->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2450 | portp->rc = rc; |
| 2451 | clear_bit(ST_CMDING, &portp->state); |
| 2452 | stli_dodelaycmd(portp, cp); |
| 2453 | wake_up_interruptible(&portp->raw_wait); |
| 2454 | } |
| 2455 | } |
| 2456 | |
| 2457 | /* |
| 2458 | * Check for any notification messages ready. This includes lots of |
| 2459 | * different types of events - RX chars ready, RX break received, |
| 2460 | * TX data low or empty in the slave, modem signals changed state. |
| 2461 | */ |
| 2462 | donerx = 0; |
| 2463 | |
| 2464 | if (ap->notify) { |
| 2465 | nt = ap->changed; |
| 2466 | ap->notify = 0; |
| 2467 | tty = portp->tty; |
| 2468 | |
| 2469 | if (nt.signal & SG_DCD) { |
| 2470 | oldsigs = portp->sigs; |
| 2471 | portp->sigs = stli_mktiocm(nt.sigvalue); |
| 2472 | clear_bit(ST_GETSIGS, &portp->state); |
| 2473 | if ((portp->sigs & TIOCM_CD) && |
| 2474 | ((oldsigs & TIOCM_CD) == 0)) |
| 2475 | wake_up_interruptible(&portp->open_wait); |
| 2476 | if ((oldsigs & TIOCM_CD) && |
| 2477 | ((portp->sigs & TIOCM_CD) == 0)) { |
| 2478 | if (portp->flags & ASYNC_CHECK_CD) { |
| 2479 | if (tty) |
| 2480 | schedule_work(&portp->tqhangup); |
| 2481 | } |
| 2482 | } |
| 2483 | } |
| 2484 | |
| 2485 | if (nt.data & DT_TXEMPTY) |
| 2486 | clear_bit(ST_TXBUSY, &portp->state); |
| 2487 | if (nt.data & (DT_TXEMPTY | DT_TXLOW)) { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2488 | if (tty != NULL) { |
| 2489 | tty_wakeup(tty); |
| 2490 | EBRDENABLE(brdp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2491 | wake_up_interruptible(&tty->write_wait); |
| 2492 | } |
| 2493 | } |
| 2494 | |
| 2495 | if ((nt.data & DT_RXBREAK) && (portp->rxmarkmsk & BRKINT)) { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2496 | if (tty != NULL) { |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 2497 | tty_insert_flip_char(tty, 0, TTY_BREAK); |
| 2498 | if (portp->flags & ASYNC_SAK) { |
| 2499 | do_SAK(tty); |
| 2500 | EBRDENABLE(brdp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2501 | } |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 2502 | tty_schedule_flip(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2503 | } |
| 2504 | } |
| 2505 | |
| 2506 | if (nt.data & DT_RXBUSY) { |
| 2507 | donerx++; |
| 2508 | stli_read(brdp, portp); |
| 2509 | } |
| 2510 | } |
| 2511 | |
| 2512 | /* |
| 2513 | * It might seem odd that we are checking for more RX chars here. |
| 2514 | * But, we need to handle the case where the tty buffer was previously |
| 2515 | * filled, but we had more characters to pass up. The slave will not |
| 2516 | * send any more RX notify messages until the RX buffer has been emptied. |
| 2517 | * But it will leave the service bits on (since the buffer is not empty). |
| 2518 | * So from here we can try to process more RX chars. |
| 2519 | */ |
| 2520 | if ((!donerx) && test_bit(ST_RXING, &portp->state)) { |
| 2521 | clear_bit(ST_RXING, &portp->state); |
| 2522 | stli_read(brdp, portp); |
| 2523 | } |
| 2524 | |
| 2525 | return((test_bit(ST_OPENING, &portp->state) || |
| 2526 | test_bit(ST_CLOSING, &portp->state) || |
| 2527 | test_bit(ST_CMDING, &portp->state) || |
| 2528 | test_bit(ST_TXBUSY, &portp->state) || |
| 2529 | test_bit(ST_RXING, &portp->state)) ? 0 : 1); |
| 2530 | } |
| 2531 | |
| 2532 | /*****************************************************************************/ |
| 2533 | |
| 2534 | /* |
| 2535 | * Service all ports on a particular board. Assumes that the boards |
| 2536 | * shared memory is enabled, and that the page pointer is pointed |
| 2537 | * at the cdk header structure. |
| 2538 | */ |
| 2539 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 2540 | static void stli_brdpoll(struct stlibrd *brdp, cdkhdr_t __iomem *hdrp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2541 | { |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 2542 | struct stliport *portp; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2543 | unsigned char hostbits[(STL_MAXCHANS / 8) + 1]; |
| 2544 | unsigned char slavebits[(STL_MAXCHANS / 8) + 1]; |
| 2545 | unsigned char __iomem *slavep; |
| 2546 | int bitpos, bitat, bitsize; |
| 2547 | int channr, nrdevs, slavebitchange; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2548 | |
| 2549 | bitsize = brdp->bitsize; |
| 2550 | nrdevs = brdp->nrdevs; |
| 2551 | |
| 2552 | /* |
| 2553 | * Check if slave wants any service. Basically we try to do as |
| 2554 | * little work as possible here. There are 2 levels of service |
| 2555 | * bits. So if there is nothing to do we bail early. We check |
| 2556 | * 8 service bits at a time in the inner loop, so we can bypass |
| 2557 | * the lot if none of them want service. |
| 2558 | */ |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2559 | memcpy_fromio(&hostbits[0], (((unsigned char __iomem *) hdrp) + brdp->hostoffset), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2560 | bitsize); |
| 2561 | |
| 2562 | memset(&slavebits[0], 0, bitsize); |
| 2563 | slavebitchange = 0; |
| 2564 | |
| 2565 | for (bitpos = 0; (bitpos < bitsize); bitpos++) { |
| 2566 | if (hostbits[bitpos] == 0) |
| 2567 | continue; |
| 2568 | channr = bitpos * 8; |
| 2569 | for (bitat = 0x1; (channr < nrdevs); channr++, bitat <<= 1) { |
| 2570 | if (hostbits[bitpos] & bitat) { |
| 2571 | portp = brdp->ports[(channr - 1)]; |
| 2572 | if (stli_hostcmd(brdp, portp)) { |
| 2573 | slavebitchange++; |
| 2574 | slavebits[bitpos] |= bitat; |
| 2575 | } |
| 2576 | } |
| 2577 | } |
| 2578 | } |
| 2579 | |
| 2580 | /* |
| 2581 | * If any of the ports are no longer busy then update them in the |
| 2582 | * slave request bits. We need to do this after, since a host port |
| 2583 | * service may initiate more slave requests. |
| 2584 | */ |
| 2585 | if (slavebitchange) { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2586 | hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR); |
| 2587 | slavep = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2588 | for (bitpos = 0; (bitpos < bitsize); bitpos++) { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2589 | if (readb(slavebits + bitpos)) |
| 2590 | writeb(readb(slavep + bitpos) & ~slavebits[bitpos], slavebits + bitpos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2591 | } |
| 2592 | } |
| 2593 | } |
| 2594 | |
| 2595 | /*****************************************************************************/ |
| 2596 | |
| 2597 | /* |
| 2598 | * Driver poll routine. This routine polls the boards in use and passes |
| 2599 | * messages back up to host when necessary. This is actually very |
| 2600 | * CPU efficient, since we will always have the kernel poll clock, it |
| 2601 | * adds only a few cycles when idle (since board service can be |
| 2602 | * determined very easily), but when loaded generates no interrupts |
| 2603 | * (with their expensive associated context change). |
| 2604 | */ |
| 2605 | |
| 2606 | static void stli_poll(unsigned long arg) |
| 2607 | { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2608 | cdkhdr_t __iomem *hdrp; |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 2609 | struct stlibrd *brdp; |
Jiri Slaby | 1328d73 | 2006-12-08 02:39:19 -0800 | [diff] [blame] | 2610 | unsigned int brdnr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2611 | |
| 2612 | stli_timerlist.expires = STLI_TIMEOUT; |
| 2613 | add_timer(&stli_timerlist); |
| 2614 | |
| 2615 | /* |
| 2616 | * Check each board and do any servicing required. |
| 2617 | */ |
| 2618 | for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) { |
| 2619 | brdp = stli_brds[brdnr]; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2620 | if (brdp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2621 | continue; |
| 2622 | if ((brdp->state & BST_STARTED) == 0) |
| 2623 | continue; |
| 2624 | |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2625 | spin_lock(&brd_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2626 | EBRDENABLE(brdp); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2627 | hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR); |
| 2628 | if (readb(&hdrp->hostreq)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2629 | stli_brdpoll(brdp, hdrp); |
| 2630 | EBRDDISABLE(brdp); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2631 | spin_unlock(&brd_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2632 | } |
| 2633 | } |
| 2634 | |
| 2635 | /*****************************************************************************/ |
| 2636 | |
| 2637 | /* |
| 2638 | * Translate the termios settings into the port setting structure of |
| 2639 | * the slave. |
| 2640 | */ |
| 2641 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 2642 | static void stli_mkasyport(struct stliport *portp, asyport_t *pp, struct ktermios *tiosp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2643 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2644 | memset(pp, 0, sizeof(asyport_t)); |
| 2645 | |
| 2646 | /* |
| 2647 | * Start of by setting the baud, char size, parity and stop bit info. |
| 2648 | */ |
Alan Cox | 1db27c1 | 2006-09-29 02:01:38 -0700 | [diff] [blame] | 2649 | pp->baudout = tty_get_baud_rate(portp->tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2650 | if ((tiosp->c_cflag & CBAUD) == B38400) { |
| 2651 | if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI) |
| 2652 | pp->baudout = 57600; |
| 2653 | else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI) |
| 2654 | pp->baudout = 115200; |
| 2655 | else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI) |
| 2656 | pp->baudout = 230400; |
| 2657 | else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP) |
| 2658 | pp->baudout = 460800; |
| 2659 | else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST) |
| 2660 | pp->baudout = (portp->baud_base / portp->custom_divisor); |
| 2661 | } |
| 2662 | if (pp->baudout > STL_MAXBAUD) |
| 2663 | pp->baudout = STL_MAXBAUD; |
| 2664 | pp->baudin = pp->baudout; |
| 2665 | |
| 2666 | switch (tiosp->c_cflag & CSIZE) { |
| 2667 | case CS5: |
| 2668 | pp->csize = 5; |
| 2669 | break; |
| 2670 | case CS6: |
| 2671 | pp->csize = 6; |
| 2672 | break; |
| 2673 | case CS7: |
| 2674 | pp->csize = 7; |
| 2675 | break; |
| 2676 | default: |
| 2677 | pp->csize = 8; |
| 2678 | break; |
| 2679 | } |
| 2680 | |
| 2681 | if (tiosp->c_cflag & CSTOPB) |
| 2682 | pp->stopbs = PT_STOP2; |
| 2683 | else |
| 2684 | pp->stopbs = PT_STOP1; |
| 2685 | |
| 2686 | if (tiosp->c_cflag & PARENB) { |
| 2687 | if (tiosp->c_cflag & PARODD) |
| 2688 | pp->parity = PT_ODDPARITY; |
| 2689 | else |
| 2690 | pp->parity = PT_EVENPARITY; |
| 2691 | } else { |
| 2692 | pp->parity = PT_NOPARITY; |
| 2693 | } |
| 2694 | |
| 2695 | /* |
| 2696 | * Set up any flow control options enabled. |
| 2697 | */ |
| 2698 | if (tiosp->c_iflag & IXON) { |
| 2699 | pp->flow |= F_IXON; |
| 2700 | if (tiosp->c_iflag & IXANY) |
| 2701 | pp->flow |= F_IXANY; |
| 2702 | } |
| 2703 | if (tiosp->c_cflag & CRTSCTS) |
| 2704 | pp->flow |= (F_RTSFLOW | F_CTSFLOW); |
| 2705 | |
| 2706 | pp->startin = tiosp->c_cc[VSTART]; |
| 2707 | pp->stopin = tiosp->c_cc[VSTOP]; |
| 2708 | pp->startout = tiosp->c_cc[VSTART]; |
| 2709 | pp->stopout = tiosp->c_cc[VSTOP]; |
| 2710 | |
| 2711 | /* |
| 2712 | * Set up the RX char marking mask with those RX error types we must |
| 2713 | * catch. We can get the slave to help us out a little here, it will |
| 2714 | * ignore parity errors and breaks for us, and mark parity errors in |
| 2715 | * the data stream. |
| 2716 | */ |
| 2717 | if (tiosp->c_iflag & IGNPAR) |
| 2718 | pp->iflag |= FI_IGNRXERRS; |
| 2719 | if (tiosp->c_iflag & IGNBRK) |
| 2720 | pp->iflag |= FI_IGNBREAK; |
| 2721 | |
| 2722 | portp->rxmarkmsk = 0; |
| 2723 | if (tiosp->c_iflag & (INPCK | PARMRK)) |
| 2724 | pp->iflag |= FI_1MARKRXERRS; |
| 2725 | if (tiosp->c_iflag & BRKINT) |
| 2726 | portp->rxmarkmsk |= BRKINT; |
| 2727 | |
| 2728 | /* |
| 2729 | * Set up clocal processing as required. |
| 2730 | */ |
| 2731 | if (tiosp->c_cflag & CLOCAL) |
| 2732 | portp->flags &= ~ASYNC_CHECK_CD; |
| 2733 | else |
| 2734 | portp->flags |= ASYNC_CHECK_CD; |
| 2735 | |
| 2736 | /* |
| 2737 | * Transfer any persistent flags into the asyport structure. |
| 2738 | */ |
| 2739 | pp->pflag = (portp->pflag & 0xffff); |
| 2740 | pp->vmin = (portp->pflag & P_RXIMIN) ? 1 : 0; |
| 2741 | pp->vtime = (portp->pflag & P_RXITIME) ? 1 : 0; |
| 2742 | pp->cc[1] = (portp->pflag & P_RXTHOLD) ? 1 : 0; |
| 2743 | } |
| 2744 | |
| 2745 | /*****************************************************************************/ |
| 2746 | |
| 2747 | /* |
| 2748 | * Construct a slave signals structure for setting the DTR and RTS |
| 2749 | * signals as specified. |
| 2750 | */ |
| 2751 | |
| 2752 | static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts) |
| 2753 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2754 | memset(sp, 0, sizeof(asysigs_t)); |
| 2755 | if (dtr >= 0) { |
| 2756 | sp->signal |= SG_DTR; |
| 2757 | sp->sigvalue |= ((dtr > 0) ? SG_DTR : 0); |
| 2758 | } |
| 2759 | if (rts >= 0) { |
| 2760 | sp->signal |= SG_RTS; |
| 2761 | sp->sigvalue |= ((rts > 0) ? SG_RTS : 0); |
| 2762 | } |
| 2763 | } |
| 2764 | |
| 2765 | /*****************************************************************************/ |
| 2766 | |
| 2767 | /* |
| 2768 | * Convert the signals returned from the slave into a local TIOCM type |
| 2769 | * signals value. We keep them locally in TIOCM format. |
| 2770 | */ |
| 2771 | |
| 2772 | static long stli_mktiocm(unsigned long sigvalue) |
| 2773 | { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2774 | long tiocm = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2775 | tiocm |= ((sigvalue & SG_DCD) ? TIOCM_CD : 0); |
| 2776 | tiocm |= ((sigvalue & SG_CTS) ? TIOCM_CTS : 0); |
| 2777 | tiocm |= ((sigvalue & SG_RI) ? TIOCM_RI : 0); |
| 2778 | tiocm |= ((sigvalue & SG_DSR) ? TIOCM_DSR : 0); |
| 2779 | tiocm |= ((sigvalue & SG_DTR) ? TIOCM_DTR : 0); |
| 2780 | tiocm |= ((sigvalue & SG_RTS) ? TIOCM_RTS : 0); |
| 2781 | return(tiocm); |
| 2782 | } |
| 2783 | |
| 2784 | /*****************************************************************************/ |
| 2785 | |
| 2786 | /* |
| 2787 | * All panels and ports actually attached have been worked out. All |
| 2788 | * we need to do here is set up the appropriate per port data structures. |
| 2789 | */ |
| 2790 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 2791 | static int stli_initports(struct stlibrd *brdp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2792 | { |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 2793 | struct stliport *portp; |
Jiri Slaby | 1328d73 | 2006-12-08 02:39:19 -0800 | [diff] [blame] | 2794 | unsigned int i, panelnr, panelport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2795 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2796 | for (i = 0, panelnr = 0, panelport = 0; (i < brdp->nrports); i++) { |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 2797 | portp = kzalloc(sizeof(struct stliport), GFP_KERNEL); |
Tobias Klauser | b0b4ed7 | 2006-03-31 02:30:56 -0800 | [diff] [blame] | 2798 | if (!portp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2799 | printk("STALLION: failed to allocate port structure\n"); |
| 2800 | continue; |
| 2801 | } |
| 2802 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2803 | portp->magic = STLI_PORTMAGIC; |
| 2804 | portp->portnr = i; |
| 2805 | portp->brdnr = brdp->brdnr; |
| 2806 | portp->panelnr = panelnr; |
| 2807 | portp->baud_base = STL_BAUDBASE; |
| 2808 | portp->close_delay = STL_CLOSEDELAY; |
| 2809 | portp->closing_wait = 30 * HZ; |
Al Viro | 3e577a8 | 2006-12-06 18:41:45 +0000 | [diff] [blame] | 2810 | INIT_WORK(&portp->tqhangup, stli_dohangup); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2811 | init_waitqueue_head(&portp->open_wait); |
| 2812 | init_waitqueue_head(&portp->close_wait); |
| 2813 | init_waitqueue_head(&portp->raw_wait); |
| 2814 | panelport++; |
| 2815 | if (panelport >= brdp->panels[panelnr]) { |
| 2816 | panelport = 0; |
| 2817 | panelnr++; |
| 2818 | } |
| 2819 | brdp->ports[i] = portp; |
| 2820 | } |
| 2821 | |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2822 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2823 | } |
| 2824 | |
| 2825 | /*****************************************************************************/ |
| 2826 | |
| 2827 | /* |
| 2828 | * All the following routines are board specific hardware operations. |
| 2829 | */ |
| 2830 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 2831 | static void stli_ecpinit(struct stlibrd *brdp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2832 | { |
| 2833 | unsigned long memconf; |
| 2834 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2835 | outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR)); |
| 2836 | udelay(10); |
| 2837 | outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR)); |
| 2838 | udelay(100); |
| 2839 | |
| 2840 | memconf = (brdp->memaddr & ECP_ATADDRMASK) >> ECP_ATADDRSHFT; |
| 2841 | outb(memconf, (brdp->iobase + ECP_ATMEMAR)); |
| 2842 | } |
| 2843 | |
| 2844 | /*****************************************************************************/ |
| 2845 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 2846 | static void stli_ecpenable(struct stlibrd *brdp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2847 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2848 | outb(ECP_ATENABLE, (brdp->iobase + ECP_ATCONFR)); |
| 2849 | } |
| 2850 | |
| 2851 | /*****************************************************************************/ |
| 2852 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 2853 | static void stli_ecpdisable(struct stlibrd *brdp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2854 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2855 | outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR)); |
| 2856 | } |
| 2857 | |
| 2858 | /*****************************************************************************/ |
| 2859 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 2860 | static void __iomem *stli_ecpgetmemptr(struct stlibrd *brdp, unsigned long offset, int line) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2861 | { |
Al Viro | 29756fa | 2006-10-10 22:47:27 +0100 | [diff] [blame] | 2862 | void __iomem *ptr; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2863 | unsigned char val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2864 | |
| 2865 | if (offset > brdp->memsize) { |
| 2866 | printk(KERN_ERR "STALLION: shared memory pointer=%x out of " |
| 2867 | "range at line=%d(%d), brd=%d\n", |
| 2868 | (int) offset, line, __LINE__, brdp->brdnr); |
| 2869 | ptr = NULL; |
| 2870 | val = 0; |
| 2871 | } else { |
| 2872 | ptr = brdp->membase + (offset % ECP_ATPAGESIZE); |
| 2873 | val = (unsigned char) (offset / ECP_ATPAGESIZE); |
| 2874 | } |
| 2875 | outb(val, (brdp->iobase + ECP_ATMEMPR)); |
| 2876 | return(ptr); |
| 2877 | } |
| 2878 | |
| 2879 | /*****************************************************************************/ |
| 2880 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 2881 | static void stli_ecpreset(struct stlibrd *brdp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2882 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2883 | outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR)); |
| 2884 | udelay(10); |
| 2885 | outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR)); |
| 2886 | udelay(500); |
| 2887 | } |
| 2888 | |
| 2889 | /*****************************************************************************/ |
| 2890 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 2891 | static void stli_ecpintr(struct stlibrd *brdp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2892 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2893 | outb(0x1, brdp->iobase); |
| 2894 | } |
| 2895 | |
| 2896 | /*****************************************************************************/ |
| 2897 | |
| 2898 | /* |
| 2899 | * The following set of functions act on ECP EISA boards. |
| 2900 | */ |
| 2901 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 2902 | static void stli_ecpeiinit(struct stlibrd *brdp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2903 | { |
| 2904 | unsigned long memconf; |
| 2905 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2906 | outb(0x1, (brdp->iobase + ECP_EIBRDENAB)); |
| 2907 | outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR)); |
| 2908 | udelay(10); |
| 2909 | outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR)); |
| 2910 | udelay(500); |
| 2911 | |
| 2912 | memconf = (brdp->memaddr & ECP_EIADDRMASKL) >> ECP_EIADDRSHFTL; |
| 2913 | outb(memconf, (brdp->iobase + ECP_EIMEMARL)); |
| 2914 | memconf = (brdp->memaddr & ECP_EIADDRMASKH) >> ECP_EIADDRSHFTH; |
| 2915 | outb(memconf, (brdp->iobase + ECP_EIMEMARH)); |
| 2916 | } |
| 2917 | |
| 2918 | /*****************************************************************************/ |
| 2919 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 2920 | static void stli_ecpeienable(struct stlibrd *brdp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2921 | { |
| 2922 | outb(ECP_EIENABLE, (brdp->iobase + ECP_EICONFR)); |
| 2923 | } |
| 2924 | |
| 2925 | /*****************************************************************************/ |
| 2926 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 2927 | static void stli_ecpeidisable(struct stlibrd *brdp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2928 | { |
| 2929 | outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR)); |
| 2930 | } |
| 2931 | |
| 2932 | /*****************************************************************************/ |
| 2933 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 2934 | static void __iomem *stli_ecpeigetmemptr(struct stlibrd *brdp, unsigned long offset, int line) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2935 | { |
Al Viro | 29756fa | 2006-10-10 22:47:27 +0100 | [diff] [blame] | 2936 | void __iomem *ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2937 | unsigned char val; |
| 2938 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2939 | if (offset > brdp->memsize) { |
| 2940 | printk(KERN_ERR "STALLION: shared memory pointer=%x out of " |
| 2941 | "range at line=%d(%d), brd=%d\n", |
| 2942 | (int) offset, line, __LINE__, brdp->brdnr); |
| 2943 | ptr = NULL; |
| 2944 | val = 0; |
| 2945 | } else { |
| 2946 | ptr = brdp->membase + (offset % ECP_EIPAGESIZE); |
| 2947 | if (offset < ECP_EIPAGESIZE) |
| 2948 | val = ECP_EIENABLE; |
| 2949 | else |
| 2950 | val = ECP_EIENABLE | 0x40; |
| 2951 | } |
| 2952 | outb(val, (brdp->iobase + ECP_EICONFR)); |
| 2953 | return(ptr); |
| 2954 | } |
| 2955 | |
| 2956 | /*****************************************************************************/ |
| 2957 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 2958 | static void stli_ecpeireset(struct stlibrd *brdp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2959 | { |
| 2960 | outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR)); |
| 2961 | udelay(10); |
| 2962 | outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR)); |
| 2963 | udelay(500); |
| 2964 | } |
| 2965 | |
| 2966 | /*****************************************************************************/ |
| 2967 | |
| 2968 | /* |
| 2969 | * The following set of functions act on ECP MCA boards. |
| 2970 | */ |
| 2971 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 2972 | static void stli_ecpmcenable(struct stlibrd *brdp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2973 | { |
| 2974 | outb(ECP_MCENABLE, (brdp->iobase + ECP_MCCONFR)); |
| 2975 | } |
| 2976 | |
| 2977 | /*****************************************************************************/ |
| 2978 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 2979 | static void stli_ecpmcdisable(struct stlibrd *brdp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2980 | { |
| 2981 | outb(ECP_MCDISABLE, (brdp->iobase + ECP_MCCONFR)); |
| 2982 | } |
| 2983 | |
| 2984 | /*****************************************************************************/ |
| 2985 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 2986 | static void __iomem *stli_ecpmcgetmemptr(struct stlibrd *brdp, unsigned long offset, int line) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2987 | { |
Al Viro | 29756fa | 2006-10-10 22:47:27 +0100 | [diff] [blame] | 2988 | void __iomem *ptr; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 2989 | unsigned char val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2990 | |
| 2991 | if (offset > brdp->memsize) { |
| 2992 | printk(KERN_ERR "STALLION: shared memory pointer=%x out of " |
| 2993 | "range at line=%d(%d), brd=%d\n", |
| 2994 | (int) offset, line, __LINE__, brdp->brdnr); |
| 2995 | ptr = NULL; |
| 2996 | val = 0; |
| 2997 | } else { |
| 2998 | ptr = brdp->membase + (offset % ECP_MCPAGESIZE); |
| 2999 | val = ((unsigned char) (offset / ECP_MCPAGESIZE)) | ECP_MCENABLE; |
| 3000 | } |
| 3001 | outb(val, (brdp->iobase + ECP_MCCONFR)); |
| 3002 | return(ptr); |
| 3003 | } |
| 3004 | |
| 3005 | /*****************************************************************************/ |
| 3006 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 3007 | static void stli_ecpmcreset(struct stlibrd *brdp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3008 | { |
| 3009 | outb(ECP_MCSTOP, (brdp->iobase + ECP_MCCONFR)); |
| 3010 | udelay(10); |
| 3011 | outb(ECP_MCDISABLE, (brdp->iobase + ECP_MCCONFR)); |
| 3012 | udelay(500); |
| 3013 | } |
| 3014 | |
| 3015 | /*****************************************************************************/ |
| 3016 | |
| 3017 | /* |
| 3018 | * The following set of functions act on ECP PCI boards. |
| 3019 | */ |
| 3020 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 3021 | static void stli_ecppciinit(struct stlibrd *brdp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3022 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3023 | outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR)); |
| 3024 | udelay(10); |
| 3025 | outb(0, (brdp->iobase + ECP_PCICONFR)); |
| 3026 | udelay(500); |
| 3027 | } |
| 3028 | |
| 3029 | /*****************************************************************************/ |
| 3030 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 3031 | static void __iomem *stli_ecppcigetmemptr(struct stlibrd *brdp, unsigned long offset, int line) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3032 | { |
Al Viro | 29756fa | 2006-10-10 22:47:27 +0100 | [diff] [blame] | 3033 | void __iomem *ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3034 | unsigned char val; |
| 3035 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3036 | if (offset > brdp->memsize) { |
| 3037 | printk(KERN_ERR "STALLION: shared memory pointer=%x out of " |
| 3038 | "range at line=%d(%d), board=%d\n", |
| 3039 | (int) offset, line, __LINE__, brdp->brdnr); |
| 3040 | ptr = NULL; |
| 3041 | val = 0; |
| 3042 | } else { |
| 3043 | ptr = brdp->membase + (offset % ECP_PCIPAGESIZE); |
| 3044 | val = (offset / ECP_PCIPAGESIZE) << 1; |
| 3045 | } |
| 3046 | outb(val, (brdp->iobase + ECP_PCICONFR)); |
| 3047 | return(ptr); |
| 3048 | } |
| 3049 | |
| 3050 | /*****************************************************************************/ |
| 3051 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 3052 | static void stli_ecppcireset(struct stlibrd *brdp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3053 | { |
| 3054 | outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR)); |
| 3055 | udelay(10); |
| 3056 | outb(0, (brdp->iobase + ECP_PCICONFR)); |
| 3057 | udelay(500); |
| 3058 | } |
| 3059 | |
| 3060 | /*****************************************************************************/ |
| 3061 | |
| 3062 | /* |
| 3063 | * The following routines act on ONboards. |
| 3064 | */ |
| 3065 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 3066 | static void stli_onbinit(struct stlibrd *brdp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3067 | { |
| 3068 | unsigned long memconf; |
| 3069 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3070 | outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR)); |
| 3071 | udelay(10); |
| 3072 | outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR)); |
| 3073 | mdelay(1000); |
| 3074 | |
| 3075 | memconf = (brdp->memaddr & ONB_ATADDRMASK) >> ONB_ATADDRSHFT; |
| 3076 | outb(memconf, (brdp->iobase + ONB_ATMEMAR)); |
| 3077 | outb(0x1, brdp->iobase); |
| 3078 | mdelay(1); |
| 3079 | } |
| 3080 | |
| 3081 | /*****************************************************************************/ |
| 3082 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 3083 | static void stli_onbenable(struct stlibrd *brdp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3084 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3085 | outb((brdp->enabval | ONB_ATENABLE), (brdp->iobase + ONB_ATCONFR)); |
| 3086 | } |
| 3087 | |
| 3088 | /*****************************************************************************/ |
| 3089 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 3090 | static void stli_onbdisable(struct stlibrd *brdp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3091 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3092 | outb((brdp->enabval | ONB_ATDISABLE), (brdp->iobase + ONB_ATCONFR)); |
| 3093 | } |
| 3094 | |
| 3095 | /*****************************************************************************/ |
| 3096 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 3097 | static void __iomem *stli_onbgetmemptr(struct stlibrd *brdp, unsigned long offset, int line) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3098 | { |
Al Viro | 29756fa | 2006-10-10 22:47:27 +0100 | [diff] [blame] | 3099 | void __iomem *ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3100 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3101 | if (offset > brdp->memsize) { |
| 3102 | printk(KERN_ERR "STALLION: shared memory pointer=%x out of " |
| 3103 | "range at line=%d(%d), brd=%d\n", |
| 3104 | (int) offset, line, __LINE__, brdp->brdnr); |
| 3105 | ptr = NULL; |
| 3106 | } else { |
| 3107 | ptr = brdp->membase + (offset % ONB_ATPAGESIZE); |
| 3108 | } |
| 3109 | return(ptr); |
| 3110 | } |
| 3111 | |
| 3112 | /*****************************************************************************/ |
| 3113 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 3114 | static void stli_onbreset(struct stlibrd *brdp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3115 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3116 | outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR)); |
| 3117 | udelay(10); |
| 3118 | outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR)); |
| 3119 | mdelay(1000); |
| 3120 | } |
| 3121 | |
| 3122 | /*****************************************************************************/ |
| 3123 | |
| 3124 | /* |
| 3125 | * The following routines act on ONboard EISA. |
| 3126 | */ |
| 3127 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 3128 | static void stli_onbeinit(struct stlibrd *brdp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3129 | { |
| 3130 | unsigned long memconf; |
| 3131 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3132 | outb(0x1, (brdp->iobase + ONB_EIBRDENAB)); |
| 3133 | outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR)); |
| 3134 | udelay(10); |
| 3135 | outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR)); |
| 3136 | mdelay(1000); |
| 3137 | |
| 3138 | memconf = (brdp->memaddr & ONB_EIADDRMASKL) >> ONB_EIADDRSHFTL; |
| 3139 | outb(memconf, (brdp->iobase + ONB_EIMEMARL)); |
| 3140 | memconf = (brdp->memaddr & ONB_EIADDRMASKH) >> ONB_EIADDRSHFTH; |
| 3141 | outb(memconf, (brdp->iobase + ONB_EIMEMARH)); |
| 3142 | outb(0x1, brdp->iobase); |
| 3143 | mdelay(1); |
| 3144 | } |
| 3145 | |
| 3146 | /*****************************************************************************/ |
| 3147 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 3148 | static void stli_onbeenable(struct stlibrd *brdp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3149 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3150 | outb(ONB_EIENABLE, (brdp->iobase + ONB_EICONFR)); |
| 3151 | } |
| 3152 | |
| 3153 | /*****************************************************************************/ |
| 3154 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 3155 | static void stli_onbedisable(struct stlibrd *brdp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3156 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3157 | outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR)); |
| 3158 | } |
| 3159 | |
| 3160 | /*****************************************************************************/ |
| 3161 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 3162 | static void __iomem *stli_onbegetmemptr(struct stlibrd *brdp, unsigned long offset, int line) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3163 | { |
Al Viro | 29756fa | 2006-10-10 22:47:27 +0100 | [diff] [blame] | 3164 | void __iomem *ptr; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3165 | unsigned char val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3166 | |
| 3167 | if (offset > brdp->memsize) { |
| 3168 | printk(KERN_ERR "STALLION: shared memory pointer=%x out of " |
| 3169 | "range at line=%d(%d), brd=%d\n", |
| 3170 | (int) offset, line, __LINE__, brdp->brdnr); |
| 3171 | ptr = NULL; |
| 3172 | val = 0; |
| 3173 | } else { |
| 3174 | ptr = brdp->membase + (offset % ONB_EIPAGESIZE); |
| 3175 | if (offset < ONB_EIPAGESIZE) |
| 3176 | val = ONB_EIENABLE; |
| 3177 | else |
| 3178 | val = ONB_EIENABLE | 0x40; |
| 3179 | } |
| 3180 | outb(val, (brdp->iobase + ONB_EICONFR)); |
| 3181 | return(ptr); |
| 3182 | } |
| 3183 | |
| 3184 | /*****************************************************************************/ |
| 3185 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 3186 | static void stli_onbereset(struct stlibrd *brdp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3187 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3188 | outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR)); |
| 3189 | udelay(10); |
| 3190 | outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR)); |
| 3191 | mdelay(1000); |
| 3192 | } |
| 3193 | |
| 3194 | /*****************************************************************************/ |
| 3195 | |
| 3196 | /* |
| 3197 | * The following routines act on Brumby boards. |
| 3198 | */ |
| 3199 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 3200 | static void stli_bbyinit(struct stlibrd *brdp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3201 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3202 | outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR)); |
| 3203 | udelay(10); |
| 3204 | outb(0, (brdp->iobase + BBY_ATCONFR)); |
| 3205 | mdelay(1000); |
| 3206 | outb(0x1, brdp->iobase); |
| 3207 | mdelay(1); |
| 3208 | } |
| 3209 | |
| 3210 | /*****************************************************************************/ |
| 3211 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 3212 | static void __iomem *stli_bbygetmemptr(struct stlibrd *brdp, unsigned long offset, int line) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3213 | { |
Al Viro | 29756fa | 2006-10-10 22:47:27 +0100 | [diff] [blame] | 3214 | void __iomem *ptr; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3215 | unsigned char val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3216 | |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3217 | BUG_ON(offset > brdp->memsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3218 | |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3219 | ptr = brdp->membase + (offset % BBY_PAGESIZE); |
| 3220 | val = (unsigned char) (offset / BBY_PAGESIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3221 | outb(val, (brdp->iobase + BBY_ATCONFR)); |
| 3222 | return(ptr); |
| 3223 | } |
| 3224 | |
| 3225 | /*****************************************************************************/ |
| 3226 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 3227 | static void stli_bbyreset(struct stlibrd *brdp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3228 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3229 | outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR)); |
| 3230 | udelay(10); |
| 3231 | outb(0, (brdp->iobase + BBY_ATCONFR)); |
| 3232 | mdelay(1000); |
| 3233 | } |
| 3234 | |
| 3235 | /*****************************************************************************/ |
| 3236 | |
| 3237 | /* |
| 3238 | * The following routines act on original old Stallion boards. |
| 3239 | */ |
| 3240 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 3241 | static void stli_stalinit(struct stlibrd *brdp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3242 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3243 | outb(0x1, brdp->iobase); |
| 3244 | mdelay(1000); |
| 3245 | } |
| 3246 | |
| 3247 | /*****************************************************************************/ |
| 3248 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 3249 | static void __iomem *stli_stalgetmemptr(struct stlibrd *brdp, unsigned long offset, int line) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3250 | { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3251 | BUG_ON(offset > brdp->memsize); |
| 3252 | return brdp->membase + (offset % STAL_PAGESIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3253 | } |
| 3254 | |
| 3255 | /*****************************************************************************/ |
| 3256 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 3257 | static void stli_stalreset(struct stlibrd *brdp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3258 | { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3259 | u32 __iomem *vecp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3260 | |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3261 | vecp = (u32 __iomem *) (brdp->membase + 0x30); |
| 3262 | writel(0xffff0000, vecp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3263 | outb(0, brdp->iobase); |
| 3264 | mdelay(1000); |
| 3265 | } |
| 3266 | |
| 3267 | /*****************************************************************************/ |
| 3268 | |
| 3269 | /* |
| 3270 | * Try to find an ECP board and initialize it. This handles only ECP |
| 3271 | * board types. |
| 3272 | */ |
| 3273 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 3274 | static int stli_initecp(struct stlibrd *brdp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3275 | { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3276 | cdkecpsig_t sig; |
| 3277 | cdkecpsig_t __iomem *sigsp; |
| 3278 | unsigned int status, nxtid; |
| 3279 | char *name; |
| 3280 | int panelnr, nrports; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3281 | |
| 3282 | if (!request_region(brdp->iobase, brdp->iosize, "istallion")) |
| 3283 | return -EIO; |
| 3284 | |
| 3285 | if ((brdp->iobase == 0) || (brdp->memaddr == 0)) |
| 3286 | { |
| 3287 | release_region(brdp->iobase, brdp->iosize); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3288 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3289 | } |
| 3290 | |
| 3291 | brdp->iosize = ECP_IOSIZE; |
| 3292 | |
| 3293 | /* |
| 3294 | * Based on the specific board type setup the common vars to access |
| 3295 | * and enable shared memory. Set all board specific information now |
| 3296 | * as well. |
| 3297 | */ |
| 3298 | switch (brdp->brdtype) { |
| 3299 | case BRD_ECP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3300 | brdp->memsize = ECP_MEMSIZE; |
| 3301 | brdp->pagesize = ECP_ATPAGESIZE; |
| 3302 | brdp->init = stli_ecpinit; |
| 3303 | brdp->enable = stli_ecpenable; |
| 3304 | brdp->reenable = stli_ecpenable; |
| 3305 | brdp->disable = stli_ecpdisable; |
| 3306 | brdp->getmemptr = stli_ecpgetmemptr; |
| 3307 | brdp->intr = stli_ecpintr; |
| 3308 | brdp->reset = stli_ecpreset; |
| 3309 | name = "serial(EC8/64)"; |
| 3310 | break; |
| 3311 | |
| 3312 | case BRD_ECPE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3313 | brdp->memsize = ECP_MEMSIZE; |
| 3314 | brdp->pagesize = ECP_EIPAGESIZE; |
| 3315 | brdp->init = stli_ecpeiinit; |
| 3316 | brdp->enable = stli_ecpeienable; |
| 3317 | brdp->reenable = stli_ecpeienable; |
| 3318 | brdp->disable = stli_ecpeidisable; |
| 3319 | brdp->getmemptr = stli_ecpeigetmemptr; |
| 3320 | brdp->intr = stli_ecpintr; |
| 3321 | brdp->reset = stli_ecpeireset; |
| 3322 | name = "serial(EC8/64-EI)"; |
| 3323 | break; |
| 3324 | |
| 3325 | case BRD_ECPMC: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3326 | brdp->memsize = ECP_MEMSIZE; |
| 3327 | brdp->pagesize = ECP_MCPAGESIZE; |
| 3328 | brdp->init = NULL; |
| 3329 | brdp->enable = stli_ecpmcenable; |
| 3330 | brdp->reenable = stli_ecpmcenable; |
| 3331 | brdp->disable = stli_ecpmcdisable; |
| 3332 | brdp->getmemptr = stli_ecpmcgetmemptr; |
| 3333 | brdp->intr = stli_ecpintr; |
| 3334 | brdp->reset = stli_ecpmcreset; |
| 3335 | name = "serial(EC8/64-MCA)"; |
| 3336 | break; |
| 3337 | |
| 3338 | case BRD_ECPPCI: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3339 | brdp->memsize = ECP_PCIMEMSIZE; |
| 3340 | brdp->pagesize = ECP_PCIPAGESIZE; |
| 3341 | brdp->init = stli_ecppciinit; |
| 3342 | brdp->enable = NULL; |
| 3343 | brdp->reenable = NULL; |
| 3344 | brdp->disable = NULL; |
| 3345 | brdp->getmemptr = stli_ecppcigetmemptr; |
| 3346 | brdp->intr = stli_ecpintr; |
| 3347 | brdp->reset = stli_ecppcireset; |
| 3348 | name = "serial(EC/RA-PCI)"; |
| 3349 | break; |
| 3350 | |
| 3351 | default: |
| 3352 | release_region(brdp->iobase, brdp->iosize); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3353 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3354 | } |
| 3355 | |
| 3356 | /* |
| 3357 | * The per-board operations structure is all set up, so now let's go |
| 3358 | * and get the board operational. Firstly initialize board configuration |
| 3359 | * registers. Set the memory mapping info so we can get at the boards |
| 3360 | * shared memory. |
| 3361 | */ |
| 3362 | EBRDINIT(brdp); |
| 3363 | |
| 3364 | brdp->membase = ioremap(brdp->memaddr, brdp->memsize); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3365 | if (brdp->membase == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3366 | { |
| 3367 | release_region(brdp->iobase, brdp->iosize); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3368 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3369 | } |
| 3370 | |
| 3371 | /* |
| 3372 | * Now that all specific code is set up, enable the shared memory and |
| 3373 | * look for the a signature area that will tell us exactly what board |
| 3374 | * this is, and what it is connected to it. |
| 3375 | */ |
| 3376 | EBRDENABLE(brdp); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3377 | sigsp = (cdkecpsig_t __iomem *) EBRDGETMEMPTR(brdp, CDK_SIGADDR); |
Al Viro | 634965f | 2006-09-23 01:20:31 +0100 | [diff] [blame] | 3378 | memcpy_fromio(&sig, sigsp, sizeof(cdkecpsig_t)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3379 | EBRDDISABLE(brdp); |
| 3380 | |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3381 | if (sig.magic != cpu_to_le32(ECP_MAGIC)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3382 | { |
| 3383 | release_region(brdp->iobase, brdp->iosize); |
Amol Lad | aa8a8d6 | 2006-12-06 20:35:22 -0800 | [diff] [blame] | 3384 | iounmap(brdp->membase); |
| 3385 | brdp->membase = NULL; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3386 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3387 | } |
| 3388 | |
| 3389 | /* |
| 3390 | * Scan through the signature looking at the panels connected to the |
| 3391 | * board. Calculate the total number of ports as we go. |
| 3392 | */ |
| 3393 | for (panelnr = 0, nxtid = 0; (panelnr < STL_MAXPANELS); panelnr++) { |
| 3394 | status = sig.panelid[nxtid]; |
| 3395 | if ((status & ECH_PNLIDMASK) != nxtid) |
| 3396 | break; |
| 3397 | |
| 3398 | brdp->panelids[panelnr] = status; |
| 3399 | nrports = (status & ECH_PNL16PORT) ? 16 : 8; |
| 3400 | if ((nrports == 16) && ((status & ECH_PNLXPID) == 0)) |
| 3401 | nxtid++; |
| 3402 | brdp->panels[panelnr] = nrports; |
| 3403 | brdp->nrports += nrports; |
| 3404 | nxtid++; |
| 3405 | brdp->nrpanels++; |
| 3406 | } |
| 3407 | |
| 3408 | |
| 3409 | brdp->state |= BST_FOUND; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3410 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3411 | } |
| 3412 | |
| 3413 | /*****************************************************************************/ |
| 3414 | |
| 3415 | /* |
| 3416 | * Try to find an ONboard, Brumby or Stallion board and initialize it. |
| 3417 | * This handles only these board types. |
| 3418 | */ |
| 3419 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 3420 | static int stli_initonb(struct stlibrd *brdp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3421 | { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3422 | cdkonbsig_t sig; |
| 3423 | cdkonbsig_t __iomem *sigsp; |
| 3424 | char *name; |
| 3425 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3426 | |
| 3427 | /* |
| 3428 | * Do a basic sanity check on the IO and memory addresses. |
| 3429 | */ |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3430 | if (brdp->iobase == 0 || brdp->memaddr == 0) |
| 3431 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3432 | |
| 3433 | brdp->iosize = ONB_IOSIZE; |
| 3434 | |
| 3435 | if (!request_region(brdp->iobase, brdp->iosize, "istallion")) |
| 3436 | return -EIO; |
| 3437 | |
| 3438 | /* |
| 3439 | * Based on the specific board type setup the common vars to access |
| 3440 | * and enable shared memory. Set all board specific information now |
| 3441 | * as well. |
| 3442 | */ |
| 3443 | switch (brdp->brdtype) { |
| 3444 | case BRD_ONBOARD: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3445 | case BRD_ONBOARD2: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3446 | brdp->memsize = ONB_MEMSIZE; |
| 3447 | brdp->pagesize = ONB_ATPAGESIZE; |
| 3448 | brdp->init = stli_onbinit; |
| 3449 | brdp->enable = stli_onbenable; |
| 3450 | brdp->reenable = stli_onbenable; |
| 3451 | brdp->disable = stli_onbdisable; |
| 3452 | brdp->getmemptr = stli_onbgetmemptr; |
| 3453 | brdp->intr = stli_ecpintr; |
| 3454 | brdp->reset = stli_onbreset; |
| 3455 | if (brdp->memaddr > 0x100000) |
| 3456 | brdp->enabval = ONB_MEMENABHI; |
| 3457 | else |
| 3458 | brdp->enabval = ONB_MEMENABLO; |
| 3459 | name = "serial(ONBoard)"; |
| 3460 | break; |
| 3461 | |
| 3462 | case BRD_ONBOARDE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3463 | brdp->memsize = ONB_EIMEMSIZE; |
| 3464 | brdp->pagesize = ONB_EIPAGESIZE; |
| 3465 | brdp->init = stli_onbeinit; |
| 3466 | brdp->enable = stli_onbeenable; |
| 3467 | brdp->reenable = stli_onbeenable; |
| 3468 | brdp->disable = stli_onbedisable; |
| 3469 | brdp->getmemptr = stli_onbegetmemptr; |
| 3470 | brdp->intr = stli_ecpintr; |
| 3471 | brdp->reset = stli_onbereset; |
| 3472 | name = "serial(ONBoard/E)"; |
| 3473 | break; |
| 3474 | |
| 3475 | case BRD_BRUMBY4: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3476 | brdp->memsize = BBY_MEMSIZE; |
| 3477 | brdp->pagesize = BBY_PAGESIZE; |
| 3478 | brdp->init = stli_bbyinit; |
| 3479 | brdp->enable = NULL; |
| 3480 | brdp->reenable = NULL; |
| 3481 | brdp->disable = NULL; |
| 3482 | brdp->getmemptr = stli_bbygetmemptr; |
| 3483 | brdp->intr = stli_ecpintr; |
| 3484 | brdp->reset = stli_bbyreset; |
| 3485 | name = "serial(Brumby)"; |
| 3486 | break; |
| 3487 | |
| 3488 | case BRD_STALLION: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3489 | brdp->memsize = STAL_MEMSIZE; |
| 3490 | brdp->pagesize = STAL_PAGESIZE; |
| 3491 | brdp->init = stli_stalinit; |
| 3492 | brdp->enable = NULL; |
| 3493 | brdp->reenable = NULL; |
| 3494 | brdp->disable = NULL; |
| 3495 | brdp->getmemptr = stli_stalgetmemptr; |
| 3496 | brdp->intr = stli_ecpintr; |
| 3497 | brdp->reset = stli_stalreset; |
| 3498 | name = "serial(Stallion)"; |
| 3499 | break; |
| 3500 | |
| 3501 | default: |
| 3502 | release_region(brdp->iobase, brdp->iosize); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3503 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3504 | } |
| 3505 | |
| 3506 | /* |
| 3507 | * The per-board operations structure is all set up, so now let's go |
| 3508 | * and get the board operational. Firstly initialize board configuration |
| 3509 | * registers. Set the memory mapping info so we can get at the boards |
| 3510 | * shared memory. |
| 3511 | */ |
| 3512 | EBRDINIT(brdp); |
| 3513 | |
| 3514 | brdp->membase = ioremap(brdp->memaddr, brdp->memsize); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3515 | if (brdp->membase == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3516 | { |
| 3517 | release_region(brdp->iobase, brdp->iosize); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3518 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3519 | } |
| 3520 | |
| 3521 | /* |
| 3522 | * Now that all specific code is set up, enable the shared memory and |
| 3523 | * look for the a signature area that will tell us exactly what board |
| 3524 | * this is, and how many ports. |
| 3525 | */ |
| 3526 | EBRDENABLE(brdp); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3527 | sigsp = (cdkonbsig_t __iomem *) EBRDGETMEMPTR(brdp, CDK_SIGADDR); |
| 3528 | memcpy_fromio(&sig, sigsp, sizeof(cdkonbsig_t)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3529 | EBRDDISABLE(brdp); |
| 3530 | |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3531 | if (sig.magic0 != cpu_to_le16(ONB_MAGIC0) || |
| 3532 | sig.magic1 != cpu_to_le16(ONB_MAGIC1) || |
| 3533 | sig.magic2 != cpu_to_le16(ONB_MAGIC2) || |
| 3534 | sig.magic3 != cpu_to_le16(ONB_MAGIC3)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3535 | { |
| 3536 | release_region(brdp->iobase, brdp->iosize); |
Amol Lad | aa8a8d6 | 2006-12-06 20:35:22 -0800 | [diff] [blame] | 3537 | iounmap(brdp->membase); |
| 3538 | brdp->membase = NULL; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3539 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3540 | } |
| 3541 | |
| 3542 | /* |
| 3543 | * Scan through the signature alive mask and calculate how many ports |
| 3544 | * there are on this board. |
| 3545 | */ |
| 3546 | brdp->nrpanels = 1; |
| 3547 | if (sig.amask1) { |
| 3548 | brdp->nrports = 32; |
| 3549 | } else { |
| 3550 | for (i = 0; (i < 16); i++) { |
| 3551 | if (((sig.amask0 << i) & 0x8000) == 0) |
| 3552 | break; |
| 3553 | } |
| 3554 | brdp->nrports = i; |
| 3555 | } |
| 3556 | brdp->panels[0] = brdp->nrports; |
| 3557 | |
| 3558 | |
| 3559 | brdp->state |= BST_FOUND; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3560 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3561 | } |
| 3562 | |
| 3563 | /*****************************************************************************/ |
| 3564 | |
| 3565 | /* |
| 3566 | * Start up a running board. This routine is only called after the |
| 3567 | * code has been down loaded to the board and is operational. It will |
| 3568 | * read in the memory map, and get the show on the road... |
| 3569 | */ |
| 3570 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 3571 | static int stli_startbrd(struct stlibrd *brdp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3572 | { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3573 | cdkhdr_t __iomem *hdrp; |
| 3574 | cdkmem_t __iomem *memp; |
| 3575 | cdkasy_t __iomem *ap; |
| 3576 | unsigned long flags; |
Jiri Slaby | 1328d73 | 2006-12-08 02:39:19 -0800 | [diff] [blame] | 3577 | unsigned int portnr, nrdevs, i; |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 3578 | struct stliport *portp; |
Jiri Slaby | 1328d73 | 2006-12-08 02:39:19 -0800 | [diff] [blame] | 3579 | int rc = 0; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3580 | u32 memoff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3581 | |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3582 | spin_lock_irqsave(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3583 | EBRDENABLE(brdp); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3584 | hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3585 | nrdevs = hdrp->nrdevs; |
| 3586 | |
| 3587 | #if 0 |
| 3588 | printk("%s(%d): CDK version %d.%d.%d --> " |
| 3589 | "nrdevs=%d memp=%x hostp=%x slavep=%x\n", |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3590 | __FILE__, __LINE__, readb(&hdrp->ver_release), readb(&hdrp->ver_modification), |
| 3591 | readb(&hdrp->ver_fix), nrdevs, (int) readl(&hdrp->memp), readl(&hdrp->hostp), |
| 3592 | readl(&hdrp->slavep)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3593 | #endif |
| 3594 | |
| 3595 | if (nrdevs < (brdp->nrports + 1)) { |
| 3596 | printk(KERN_ERR "STALLION: slave failed to allocate memory for " |
| 3597 | "all devices, devices=%d\n", nrdevs); |
| 3598 | brdp->nrports = nrdevs - 1; |
| 3599 | } |
| 3600 | brdp->nrdevs = nrdevs; |
| 3601 | brdp->hostoffset = hdrp->hostp - CDK_CDKADDR; |
| 3602 | brdp->slaveoffset = hdrp->slavep - CDK_CDKADDR; |
| 3603 | brdp->bitsize = (nrdevs + 7) / 8; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3604 | memoff = readl(&hdrp->memp); |
| 3605 | if (memoff > brdp->memsize) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3606 | printk(KERN_ERR "STALLION: corrupted shared memory region?\n"); |
| 3607 | rc = -EIO; |
| 3608 | goto stli_donestartup; |
| 3609 | } |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3610 | memp = (cdkmem_t __iomem *) EBRDGETMEMPTR(brdp, memoff); |
| 3611 | if (readw(&memp->dtype) != TYP_ASYNCTRL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3612 | printk(KERN_ERR "STALLION: no slave control device found\n"); |
| 3613 | goto stli_donestartup; |
| 3614 | } |
| 3615 | memp++; |
| 3616 | |
| 3617 | /* |
| 3618 | * Cycle through memory allocation of each port. We are guaranteed to |
| 3619 | * have all ports inside the first page of slave window, so no need to |
| 3620 | * change pages while reading memory map. |
| 3621 | */ |
| 3622 | for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++, memp++) { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3623 | if (readw(&memp->dtype) != TYP_ASYNC) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3624 | break; |
| 3625 | portp = brdp->ports[portnr]; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3626 | if (portp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3627 | break; |
| 3628 | portp->devnr = i; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3629 | portp->addr = readl(&memp->offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3630 | portp->reqbit = (unsigned char) (0x1 << (i * 8 / nrdevs)); |
| 3631 | portp->portidx = (unsigned char) (i / 8); |
| 3632 | portp->portbit = (unsigned char) (0x1 << (i % 8)); |
| 3633 | } |
| 3634 | |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3635 | writeb(0xff, &hdrp->slavereq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3636 | |
| 3637 | /* |
| 3638 | * For each port setup a local copy of the RX and TX buffer offsets |
| 3639 | * and sizes. We do this separate from the above, because we need to |
| 3640 | * move the shared memory page... |
| 3641 | */ |
| 3642 | for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++) { |
| 3643 | portp = brdp->ports[portnr]; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3644 | if (portp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3645 | break; |
| 3646 | if (portp->addr == 0) |
| 3647 | break; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3648 | ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr); |
| 3649 | if (ap != NULL) { |
| 3650 | portp->rxsize = readw(&ap->rxq.size); |
| 3651 | portp->txsize = readw(&ap->txq.size); |
| 3652 | portp->rxoffset = readl(&ap->rxq.offset); |
| 3653 | portp->txoffset = readl(&ap->txq.offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3654 | } |
| 3655 | } |
| 3656 | |
| 3657 | stli_donestartup: |
| 3658 | EBRDDISABLE(brdp); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3659 | spin_unlock_irqrestore(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3660 | |
| 3661 | if (rc == 0) |
| 3662 | brdp->state |= BST_STARTED; |
| 3663 | |
| 3664 | if (! stli_timeron) { |
| 3665 | stli_timeron++; |
| 3666 | stli_timerlist.expires = STLI_TIMEOUT; |
| 3667 | add_timer(&stli_timerlist); |
| 3668 | } |
| 3669 | |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3670 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3671 | } |
| 3672 | |
| 3673 | /*****************************************************************************/ |
| 3674 | |
| 3675 | /* |
| 3676 | * Probe and initialize the specified board. |
| 3677 | */ |
| 3678 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 3679 | static int __devinit stli_brdinit(struct stlibrd *brdp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3680 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3681 | switch (brdp->brdtype) { |
| 3682 | case BRD_ECP: |
| 3683 | case BRD_ECPE: |
| 3684 | case BRD_ECPMC: |
| 3685 | case BRD_ECPPCI: |
| 3686 | stli_initecp(brdp); |
| 3687 | break; |
| 3688 | case BRD_ONBOARD: |
| 3689 | case BRD_ONBOARDE: |
| 3690 | case BRD_ONBOARD2: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3691 | case BRD_BRUMBY4: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3692 | case BRD_STALLION: |
| 3693 | stli_initonb(brdp); |
| 3694 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3695 | default: |
| 3696 | printk(KERN_ERR "STALLION: board=%d is unknown board " |
| 3697 | "type=%d\n", brdp->brdnr, brdp->brdtype); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3698 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3699 | } |
| 3700 | |
| 3701 | if ((brdp->state & BST_FOUND) == 0) { |
| 3702 | printk(KERN_ERR "STALLION: %s board not found, board=%d " |
| 3703 | "io=%x mem=%x\n", |
| 3704 | stli_brdnames[brdp->brdtype], brdp->brdnr, |
| 3705 | brdp->iobase, (int) brdp->memaddr); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3706 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3707 | } |
| 3708 | |
| 3709 | stli_initports(brdp); |
| 3710 | printk(KERN_INFO "STALLION: %s found, board=%d io=%x mem=%x " |
| 3711 | "nrpanels=%d nrports=%d\n", stli_brdnames[brdp->brdtype], |
| 3712 | brdp->brdnr, brdp->iobase, (int) brdp->memaddr, |
| 3713 | brdp->nrpanels, brdp->nrports); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3714 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3715 | } |
| 3716 | |
Jiri Slaby | a00f33f | 2006-12-08 02:39:20 -0800 | [diff] [blame] | 3717 | #if STLI_EISAPROBE != 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3718 | /*****************************************************************************/ |
| 3719 | |
| 3720 | /* |
| 3721 | * Probe around trying to find where the EISA boards shared memory |
| 3722 | * might be. This is a bit if hack, but it is the best we can do. |
| 3723 | */ |
| 3724 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 3725 | static int stli_eisamemprobe(struct stlibrd *brdp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3726 | { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3727 | cdkecpsig_t ecpsig, __iomem *ecpsigp; |
| 3728 | cdkonbsig_t onbsig, __iomem *onbsigp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3729 | int i, foundit; |
| 3730 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3731 | /* |
| 3732 | * First up we reset the board, to get it into a known state. There |
| 3733 | * is only 2 board types here we need to worry about. Don;t use the |
| 3734 | * standard board init routine here, it programs up the shared |
| 3735 | * memory address, and we don't know it yet... |
| 3736 | */ |
| 3737 | if (brdp->brdtype == BRD_ECPE) { |
| 3738 | outb(0x1, (brdp->iobase + ECP_EIBRDENAB)); |
| 3739 | outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR)); |
| 3740 | udelay(10); |
| 3741 | outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR)); |
| 3742 | udelay(500); |
| 3743 | stli_ecpeienable(brdp); |
| 3744 | } else if (brdp->brdtype == BRD_ONBOARDE) { |
| 3745 | outb(0x1, (brdp->iobase + ONB_EIBRDENAB)); |
| 3746 | outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR)); |
| 3747 | udelay(10); |
| 3748 | outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR)); |
| 3749 | mdelay(100); |
| 3750 | outb(0x1, brdp->iobase); |
| 3751 | mdelay(1); |
| 3752 | stli_onbeenable(brdp); |
| 3753 | } else { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3754 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3755 | } |
| 3756 | |
| 3757 | foundit = 0; |
| 3758 | brdp->memsize = ECP_MEMSIZE; |
| 3759 | |
| 3760 | /* |
| 3761 | * Board shared memory is enabled, so now we have a poke around and |
| 3762 | * see if we can find it. |
| 3763 | */ |
| 3764 | for (i = 0; (i < stli_eisamempsize); i++) { |
| 3765 | brdp->memaddr = stli_eisamemprobeaddrs[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3766 | brdp->membase = ioremap(brdp->memaddr, brdp->memsize); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3767 | if (brdp->membase == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3768 | continue; |
| 3769 | |
| 3770 | if (brdp->brdtype == BRD_ECPE) { |
Al Viro | 29756fa | 2006-10-10 22:47:27 +0100 | [diff] [blame] | 3771 | ecpsigp = stli_ecpeigetmemptr(brdp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3772 | CDK_SIGADDR, __LINE__); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3773 | memcpy_fromio(&ecpsig, ecpsigp, sizeof(cdkecpsig_t)); |
| 3774 | if (ecpsig.magic == cpu_to_le32(ECP_MAGIC)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3775 | foundit = 1; |
| 3776 | } else { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3777 | onbsigp = (cdkonbsig_t __iomem *) stli_onbegetmemptr(brdp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3778 | CDK_SIGADDR, __LINE__); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3779 | memcpy_fromio(&onbsig, onbsigp, sizeof(cdkonbsig_t)); |
| 3780 | if ((onbsig.magic0 == cpu_to_le16(ONB_MAGIC0)) && |
| 3781 | (onbsig.magic1 == cpu_to_le16(ONB_MAGIC1)) && |
| 3782 | (onbsig.magic2 == cpu_to_le16(ONB_MAGIC2)) && |
| 3783 | (onbsig.magic3 == cpu_to_le16(ONB_MAGIC3))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3784 | foundit = 1; |
| 3785 | } |
| 3786 | |
| 3787 | iounmap(brdp->membase); |
| 3788 | if (foundit) |
| 3789 | break; |
| 3790 | } |
| 3791 | |
| 3792 | /* |
| 3793 | * Regardless of whether we found the shared memory or not we must |
| 3794 | * disable the region. After that return success or failure. |
| 3795 | */ |
| 3796 | if (brdp->brdtype == BRD_ECPE) |
| 3797 | stli_ecpeidisable(brdp); |
| 3798 | else |
| 3799 | stli_onbedisable(brdp); |
| 3800 | |
| 3801 | if (! foundit) { |
| 3802 | brdp->memaddr = 0; |
| 3803 | brdp->membase = NULL; |
| 3804 | printk(KERN_ERR "STALLION: failed to probe shared memory " |
| 3805 | "region for %s in EISA slot=%d\n", |
| 3806 | stli_brdnames[brdp->brdtype], (brdp->iobase >> 12)); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3807 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3808 | } |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3809 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3810 | } |
Jiri Slaby | a00f33f | 2006-12-08 02:39:20 -0800 | [diff] [blame] | 3811 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3812 | |
| 3813 | static int stli_getbrdnr(void) |
| 3814 | { |
Jiri Slaby | 1328d73 | 2006-12-08 02:39:19 -0800 | [diff] [blame] | 3815 | unsigned int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3816 | |
| 3817 | for (i = 0; i < STL_MAXBRDS; i++) { |
| 3818 | if (!stli_brds[i]) { |
| 3819 | if (i >= stli_nrbrds) |
| 3820 | stli_nrbrds = i + 1; |
| 3821 | return i; |
| 3822 | } |
| 3823 | } |
| 3824 | return -1; |
| 3825 | } |
| 3826 | |
Jiri Slaby | a00f33f | 2006-12-08 02:39:20 -0800 | [diff] [blame] | 3827 | #if STLI_EISAPROBE != 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3828 | /*****************************************************************************/ |
| 3829 | |
| 3830 | /* |
| 3831 | * Probe around and try to find any EISA boards in system. The biggest |
| 3832 | * problem here is finding out what memory address is associated with |
| 3833 | * an EISA board after it is found. The registers of the ECPE and |
| 3834 | * ONboardE are not readable - so we can't read them from there. We |
| 3835 | * don't have access to the EISA CMOS (or EISA BIOS) so we don't |
| 3836 | * actually have any way to find out the real value. The best we can |
| 3837 | * do is go probing around in the usual places hoping we can find it. |
| 3838 | */ |
| 3839 | |
| 3840 | static int stli_findeisabrds(void) |
| 3841 | { |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 3842 | struct stlibrd *brdp; |
Jiri Slaby | 1328d73 | 2006-12-08 02:39:19 -0800 | [diff] [blame] | 3843 | unsigned int iobase, eid, i; |
| 3844 | int brdnr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3845 | |
| 3846 | /* |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3847 | * Firstly check if this is an EISA system. If this is not an EISA system then |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3848 | * don't bother going any further! |
| 3849 | */ |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3850 | if (EISA_bus) |
| 3851 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3852 | |
| 3853 | /* |
| 3854 | * Looks like an EISA system, so go searching for EISA boards. |
| 3855 | */ |
| 3856 | for (iobase = 0x1000; (iobase <= 0xc000); iobase += 0x1000) { |
| 3857 | outb(0xff, (iobase + 0xc80)); |
| 3858 | eid = inb(iobase + 0xc80); |
| 3859 | eid |= inb(iobase + 0xc81) << 8; |
| 3860 | if (eid != STL_EISAID) |
| 3861 | continue; |
| 3862 | |
| 3863 | /* |
| 3864 | * We have found a board. Need to check if this board was |
| 3865 | * statically configured already (just in case!). |
| 3866 | */ |
| 3867 | for (i = 0; (i < STL_MAXBRDS); i++) { |
| 3868 | brdp = stli_brds[i]; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3869 | if (brdp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3870 | continue; |
| 3871 | if (brdp->iobase == iobase) |
| 3872 | break; |
| 3873 | } |
| 3874 | if (i < STL_MAXBRDS) |
| 3875 | continue; |
| 3876 | |
| 3877 | /* |
| 3878 | * We have found a Stallion board and it is not configured already. |
| 3879 | * Allocate a board structure and initialize it. |
| 3880 | */ |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3881 | if ((brdp = stli_allocbrd()) == NULL) |
| 3882 | return -ENOMEM; |
Jiri Slaby | 1328d73 | 2006-12-08 02:39:19 -0800 | [diff] [blame] | 3883 | brdnr = stli_getbrdnr(); |
| 3884 | if (brdnr < 0) |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3885 | return -ENOMEM; |
Jiri Slaby | 1328d73 | 2006-12-08 02:39:19 -0800 | [diff] [blame] | 3886 | brdp->brdnr = (unsigned int)brdnr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3887 | eid = inb(iobase + 0xc82); |
| 3888 | if (eid == ECP_EISAID) |
| 3889 | brdp->brdtype = BRD_ECPE; |
| 3890 | else if (eid == ONB_EISAID) |
| 3891 | brdp->brdtype = BRD_ONBOARDE; |
| 3892 | else |
| 3893 | brdp->brdtype = BRD_UNKNOWN; |
| 3894 | brdp->iobase = iobase; |
| 3895 | outb(0x1, (iobase + 0xc84)); |
| 3896 | if (stli_eisamemprobe(brdp)) |
| 3897 | outb(0, (iobase + 0xc84)); |
Jiri Slaby | b103b5c | 2006-12-08 02:39:21 -0800 | [diff] [blame^] | 3898 | stli_brds[brdp->brdnr] = brdp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3899 | stli_brdinit(brdp); |
| 3900 | } |
| 3901 | |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3902 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3903 | } |
Jiri Slaby | a00f33f | 2006-12-08 02:39:20 -0800 | [diff] [blame] | 3904 | #else |
| 3905 | static inline int stli_findeisabrds(void) { return 0; } |
| 3906 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3907 | |
| 3908 | /*****************************************************************************/ |
| 3909 | |
| 3910 | /* |
| 3911 | * Find the next available board number that is free. |
| 3912 | */ |
| 3913 | |
| 3914 | /*****************************************************************************/ |
| 3915 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3916 | /* |
| 3917 | * We have a Stallion board. Allocate a board structure and |
| 3918 | * initialize it. Read its IO and MEMORY resources from PCI |
| 3919 | * configuration space. |
| 3920 | */ |
| 3921 | |
Jiri Slaby | 845bead | 2006-12-08 02:39:17 -0800 | [diff] [blame] | 3922 | static int __devinit stli_pciprobe(struct pci_dev *pdev, |
| 3923 | const struct pci_device_id *ent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3924 | { |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 3925 | struct stlibrd *brdp; |
Jiri Slaby | 1328d73 | 2006-12-08 02:39:19 -0800 | [diff] [blame] | 3926 | int brdnr, retval = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3927 | |
Jiri Slaby | 845bead | 2006-12-08 02:39:17 -0800 | [diff] [blame] | 3928 | retval = pci_enable_device(pdev); |
| 3929 | if (retval) |
| 3930 | goto err; |
| 3931 | brdp = stli_allocbrd(); |
| 3932 | if (brdp == NULL) { |
| 3933 | retval = -ENOMEM; |
| 3934 | goto err; |
| 3935 | } |
Jiri Slaby | b103b5c | 2006-12-08 02:39:21 -0800 | [diff] [blame^] | 3936 | mutex_lock(&stli_brdslock); |
Jiri Slaby | 1328d73 | 2006-12-08 02:39:19 -0800 | [diff] [blame] | 3937 | brdnr = stli_getbrdnr(); |
Jiri Slaby | b103b5c | 2006-12-08 02:39:21 -0800 | [diff] [blame^] | 3938 | if (brdnr < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3939 | printk(KERN_INFO "STALLION: too many boards found, " |
| 3940 | "maximum supported %d\n", STL_MAXBRDS); |
Jiri Slaby | b103b5c | 2006-12-08 02:39:21 -0800 | [diff] [blame^] | 3941 | mutex_unlock(&stli_brdslock); |
Jiri Slaby | 845bead | 2006-12-08 02:39:17 -0800 | [diff] [blame] | 3942 | retval = -EIO; |
| 3943 | goto err_fr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3944 | } |
Jiri Slaby | 1328d73 | 2006-12-08 02:39:19 -0800 | [diff] [blame] | 3945 | brdp->brdnr = (unsigned int)brdnr; |
Jiri Slaby | b103b5c | 2006-12-08 02:39:21 -0800 | [diff] [blame^] | 3946 | stli_brds[brdp->brdnr] = brdp; |
| 3947 | mutex_unlock(&stli_brdslock); |
Jiri Slaby | 845bead | 2006-12-08 02:39:17 -0800 | [diff] [blame] | 3948 | brdp->brdtype = BRD_ECPPCI; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3949 | /* |
| 3950 | * We have all resources from the board, so lets setup the actual |
| 3951 | * board structure now. |
| 3952 | */ |
Jiri Slaby | 845bead | 2006-12-08 02:39:17 -0800 | [diff] [blame] | 3953 | brdp->iobase = pci_resource_start(pdev, 3); |
| 3954 | brdp->memaddr = pci_resource_start(pdev, 2); |
| 3955 | retval = stli_brdinit(brdp); |
| 3956 | if (retval) |
Jiri Slaby | b103b5c | 2006-12-08 02:39:21 -0800 | [diff] [blame^] | 3957 | goto err_null; |
Jiri Slaby | 845bead | 2006-12-08 02:39:17 -0800 | [diff] [blame] | 3958 | |
| 3959 | pci_set_drvdata(pdev, brdp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3960 | |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 3961 | return 0; |
Jiri Slaby | b103b5c | 2006-12-08 02:39:21 -0800 | [diff] [blame^] | 3962 | err_null: |
| 3963 | stli_brds[brdp->brdnr] = NULL; |
Jiri Slaby | 845bead | 2006-12-08 02:39:17 -0800 | [diff] [blame] | 3964 | err_fr: |
| 3965 | kfree(brdp); |
| 3966 | err: |
| 3967 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3968 | } |
| 3969 | |
Jiri Slaby | 845bead | 2006-12-08 02:39:17 -0800 | [diff] [blame] | 3970 | static void stli_pciremove(struct pci_dev *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3971 | { |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 3972 | struct stlibrd *brdp = pci_get_drvdata(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3973 | |
Jiri Slaby | 845bead | 2006-12-08 02:39:17 -0800 | [diff] [blame] | 3974 | stli_cleanup_ports(brdp); |
| 3975 | |
| 3976 | iounmap(brdp->membase); |
| 3977 | if (brdp->iosize > 0) |
| 3978 | release_region(brdp->iobase, brdp->iosize); |
| 3979 | |
| 3980 | stli_brds[brdp->brdnr] = NULL; |
| 3981 | kfree(brdp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3982 | } |
| 3983 | |
Jiri Slaby | 845bead | 2006-12-08 02:39:17 -0800 | [diff] [blame] | 3984 | static struct pci_driver stli_pcidriver = { |
| 3985 | .name = "istallion", |
| 3986 | .id_table = istallion_pci_tbl, |
| 3987 | .probe = stli_pciprobe, |
| 3988 | .remove = __devexit_p(stli_pciremove) |
| 3989 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3990 | /*****************************************************************************/ |
| 3991 | |
| 3992 | /* |
| 3993 | * Allocate a new board structure. Fill out the basic info in it. |
| 3994 | */ |
| 3995 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 3996 | static struct stlibrd *stli_allocbrd(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3997 | { |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 3998 | struct stlibrd *brdp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3999 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 4000 | brdp = kzalloc(sizeof(struct stlibrd), GFP_KERNEL); |
Tobias Klauser | b0b4ed7 | 2006-03-31 02:30:56 -0800 | [diff] [blame] | 4001 | if (!brdp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4002 | printk(KERN_ERR "STALLION: failed to allocate memory " |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 4003 | "(size=%Zd)\n", sizeof(struct stlibrd)); |
Tobias Klauser | b0b4ed7 | 2006-03-31 02:30:56 -0800 | [diff] [blame] | 4004 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4005 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4006 | brdp->magic = STLI_BOARDMAGIC; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4007 | return brdp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4008 | } |
| 4009 | |
| 4010 | /*****************************************************************************/ |
| 4011 | |
| 4012 | /* |
| 4013 | * Scan through all the boards in the configuration and see what we |
| 4014 | * can find. |
| 4015 | */ |
| 4016 | |
| 4017 | static int stli_initbrds(void) |
| 4018 | { |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 4019 | struct stlibrd *brdp, *nxtbrdp; |
| 4020 | struct stlconf conf; |
Jiri Slaby | 1328d73 | 2006-12-08 02:39:19 -0800 | [diff] [blame] | 4021 | unsigned int i, j; |
| 4022 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4023 | |
Jiri Slaby | a3f8d9d | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 4024 | for (stli_nrbrds = 0; stli_nrbrds < ARRAY_SIZE(stli_brdsp); |
| 4025 | stli_nrbrds++) { |
| 4026 | memset(&conf, 0, sizeof(conf)); |
| 4027 | if (stli_parsebrd(&conf, stli_brdsp[stli_nrbrds]) == 0) |
| 4028 | continue; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4029 | if ((brdp = stli_allocbrd()) == NULL) |
Jiri Slaby | a3f8d9d | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 4030 | continue; |
| 4031 | brdp->brdnr = stli_nrbrds; |
| 4032 | brdp->brdtype = conf.brdtype; |
| 4033 | brdp->iobase = conf.ioaddr1; |
| 4034 | brdp->memaddr = conf.memaddr; |
Jiri Slaby | b103b5c | 2006-12-08 02:39:21 -0800 | [diff] [blame^] | 4035 | stli_brds[brdp->brdnr] = brdp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4036 | stli_brdinit(brdp); |
| 4037 | } |
| 4038 | |
Jiri Slaby | a00f33f | 2006-12-08 02:39:20 -0800 | [diff] [blame] | 4039 | stli_findeisabrds(); |
Jiri Slaby | 845bead | 2006-12-08 02:39:17 -0800 | [diff] [blame] | 4040 | |
| 4041 | retval = pci_register_driver(&stli_pcidriver); |
| 4042 | /* TODO: check retval and do something */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4043 | |
| 4044 | /* |
| 4045 | * All found boards are initialized. Now for a little optimization, if |
| 4046 | * no boards are sharing the "shared memory" regions then we can just |
| 4047 | * leave them all enabled. This is in fact the usual case. |
| 4048 | */ |
| 4049 | stli_shared = 0; |
| 4050 | if (stli_nrbrds > 1) { |
| 4051 | for (i = 0; (i < stli_nrbrds); i++) { |
| 4052 | brdp = stli_brds[i]; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4053 | if (brdp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4054 | continue; |
| 4055 | for (j = i + 1; (j < stli_nrbrds); j++) { |
| 4056 | nxtbrdp = stli_brds[j]; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4057 | if (nxtbrdp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4058 | continue; |
| 4059 | if ((brdp->membase >= nxtbrdp->membase) && |
| 4060 | (brdp->membase <= (nxtbrdp->membase + |
| 4061 | nxtbrdp->memsize - 1))) { |
| 4062 | stli_shared++; |
| 4063 | break; |
| 4064 | } |
| 4065 | } |
| 4066 | } |
| 4067 | } |
| 4068 | |
| 4069 | if (stli_shared == 0) { |
| 4070 | for (i = 0; (i < stli_nrbrds); i++) { |
| 4071 | brdp = stli_brds[i]; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4072 | if (brdp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4073 | continue; |
| 4074 | if (brdp->state & BST_FOUND) { |
| 4075 | EBRDENABLE(brdp); |
| 4076 | brdp->enable = NULL; |
| 4077 | brdp->disable = NULL; |
| 4078 | } |
| 4079 | } |
| 4080 | } |
| 4081 | |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4082 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4083 | } |
| 4084 | |
| 4085 | /*****************************************************************************/ |
| 4086 | |
| 4087 | /* |
| 4088 | * Code to handle an "staliomem" read operation. This device is the |
| 4089 | * contents of the board shared memory. It is used for down loading |
| 4090 | * the slave image (and debugging :-) |
| 4091 | */ |
| 4092 | |
| 4093 | static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp) |
| 4094 | { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4095 | unsigned long flags; |
Al Viro | 29756fa | 2006-10-10 22:47:27 +0100 | [diff] [blame] | 4096 | void __iomem *memptr; |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 4097 | struct stlibrd *brdp; |
Jiri Slaby | 1328d73 | 2006-12-08 02:39:19 -0800 | [diff] [blame] | 4098 | unsigned int brdnr; |
| 4099 | int size, n; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4100 | void *p; |
| 4101 | loff_t off = *offp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4102 | |
Josef Sipek | a7113a9 | 2006-12-08 02:36:55 -0800 | [diff] [blame] | 4103 | brdnr = iminor(fp->f_path.dentry->d_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4104 | if (brdnr >= stli_nrbrds) |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4105 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4106 | brdp = stli_brds[brdnr]; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4107 | if (brdp == NULL) |
| 4108 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4109 | if (brdp->state == 0) |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4110 | return -ENODEV; |
| 4111 | if (off >= brdp->memsize || off + count < off) |
| 4112 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4113 | |
Jiri Slaby | a3f8d9d | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 4114 | size = min(count, (size_t)(brdp->memsize - off)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4115 | |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4116 | /* |
| 4117 | * Copy the data a page at a time |
| 4118 | */ |
| 4119 | |
| 4120 | p = (void *)__get_free_page(GFP_KERNEL); |
| 4121 | if(p == NULL) |
| 4122 | return -ENOMEM; |
| 4123 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4124 | while (size > 0) { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4125 | spin_lock_irqsave(&brd_lock, flags); |
| 4126 | EBRDENABLE(brdp); |
Al Viro | 29756fa | 2006-10-10 22:47:27 +0100 | [diff] [blame] | 4127 | memptr = EBRDGETMEMPTR(brdp, off); |
Jiri Slaby | a3f8d9d | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 4128 | n = min(size, (int)(brdp->pagesize - (((unsigned long) off) % brdp->pagesize))); |
| 4129 | n = min(n, (int)PAGE_SIZE); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4130 | memcpy_fromio(p, memptr, n); |
| 4131 | EBRDDISABLE(brdp); |
| 4132 | spin_unlock_irqrestore(&brd_lock, flags); |
| 4133 | if (copy_to_user(buf, p, n)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4134 | count = -EFAULT; |
| 4135 | goto out; |
| 4136 | } |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4137 | off += n; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4138 | buf += n; |
| 4139 | size -= n; |
| 4140 | } |
| 4141 | out: |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4142 | *offp = off; |
| 4143 | free_page((unsigned long)p); |
| 4144 | return count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4145 | } |
| 4146 | |
| 4147 | /*****************************************************************************/ |
| 4148 | |
| 4149 | /* |
| 4150 | * Code to handle an "staliomem" write operation. This device is the |
| 4151 | * contents of the board shared memory. It is used for down loading |
| 4152 | * the slave image (and debugging :-) |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4153 | * |
| 4154 | * FIXME: copy under lock |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4155 | */ |
| 4156 | |
| 4157 | static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp) |
| 4158 | { |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4159 | unsigned long flags; |
Al Viro | 29756fa | 2006-10-10 22:47:27 +0100 | [diff] [blame] | 4160 | void __iomem *memptr; |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 4161 | struct stlibrd *brdp; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4162 | char __user *chbuf; |
Jiri Slaby | 1328d73 | 2006-12-08 02:39:19 -0800 | [diff] [blame] | 4163 | unsigned int brdnr; |
| 4164 | int size, n; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4165 | void *p; |
| 4166 | loff_t off = *offp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4167 | |
Josef Sipek | a7113a9 | 2006-12-08 02:36:55 -0800 | [diff] [blame] | 4168 | brdnr = iminor(fp->f_path.dentry->d_inode); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4169 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4170 | if (brdnr >= stli_nrbrds) |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4171 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4172 | brdp = stli_brds[brdnr]; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4173 | if (brdp == NULL) |
| 4174 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4175 | if (brdp->state == 0) |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4176 | return -ENODEV; |
| 4177 | if (off >= brdp->memsize || off + count < off) |
| 4178 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4179 | |
| 4180 | chbuf = (char __user *) buf; |
Jiri Slaby | a3f8d9d | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 4181 | size = min(count, (size_t)(brdp->memsize - off)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4182 | |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4183 | /* |
| 4184 | * Copy the data a page at a time |
| 4185 | */ |
| 4186 | |
| 4187 | p = (void *)__get_free_page(GFP_KERNEL); |
| 4188 | if(p == NULL) |
| 4189 | return -ENOMEM; |
| 4190 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4191 | while (size > 0) { |
Jiri Slaby | a3f8d9d | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 4192 | n = min(size, (int)(brdp->pagesize - (((unsigned long) off) % brdp->pagesize))); |
| 4193 | n = min(n, (int)PAGE_SIZE); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4194 | if (copy_from_user(p, chbuf, n)) { |
| 4195 | if (count == 0) |
| 4196 | count = -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4197 | goto out; |
| 4198 | } |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4199 | spin_lock_irqsave(&brd_lock, flags); |
| 4200 | EBRDENABLE(brdp); |
Al Viro | 29756fa | 2006-10-10 22:47:27 +0100 | [diff] [blame] | 4201 | memptr = EBRDGETMEMPTR(brdp, off); |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4202 | memcpy_toio(memptr, p, n); |
| 4203 | EBRDDISABLE(brdp); |
| 4204 | spin_unlock_irqrestore(&brd_lock, flags); |
| 4205 | off += n; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4206 | chbuf += n; |
| 4207 | size -= n; |
| 4208 | } |
| 4209 | out: |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4210 | free_page((unsigned long) p); |
| 4211 | *offp = off; |
| 4212 | return count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4213 | } |
| 4214 | |
| 4215 | /*****************************************************************************/ |
| 4216 | |
| 4217 | /* |
| 4218 | * Return the board stats structure to user app. |
| 4219 | */ |
| 4220 | |
| 4221 | static int stli_getbrdstats(combrd_t __user *bp) |
| 4222 | { |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 4223 | struct stlibrd *brdp; |
Jiri Slaby | 1328d73 | 2006-12-08 02:39:19 -0800 | [diff] [blame] | 4224 | unsigned int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4225 | |
| 4226 | if (copy_from_user(&stli_brdstats, bp, sizeof(combrd_t))) |
| 4227 | return -EFAULT; |
| 4228 | if (stli_brdstats.brd >= STL_MAXBRDS) |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4229 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4230 | brdp = stli_brds[stli_brdstats.brd]; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4231 | if (brdp == NULL) |
| 4232 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4233 | |
| 4234 | memset(&stli_brdstats, 0, sizeof(combrd_t)); |
| 4235 | stli_brdstats.brd = brdp->brdnr; |
| 4236 | stli_brdstats.type = brdp->brdtype; |
| 4237 | stli_brdstats.hwid = 0; |
| 4238 | stli_brdstats.state = brdp->state; |
| 4239 | stli_brdstats.ioaddr = brdp->iobase; |
| 4240 | stli_brdstats.memaddr = brdp->memaddr; |
| 4241 | stli_brdstats.nrpanels = brdp->nrpanels; |
| 4242 | stli_brdstats.nrports = brdp->nrports; |
| 4243 | for (i = 0; (i < brdp->nrpanels); i++) { |
| 4244 | stli_brdstats.panels[i].panel = i; |
| 4245 | stli_brdstats.panels[i].hwid = brdp->panelids[i]; |
| 4246 | stli_brdstats.panels[i].nrports = brdp->panels[i]; |
| 4247 | } |
| 4248 | |
| 4249 | if (copy_to_user(bp, &stli_brdstats, sizeof(combrd_t))) |
| 4250 | return -EFAULT; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4251 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4252 | } |
| 4253 | |
| 4254 | /*****************************************************************************/ |
| 4255 | |
| 4256 | /* |
| 4257 | * Resolve the referenced port number into a port struct pointer. |
| 4258 | */ |
| 4259 | |
Jiri Slaby | 1328d73 | 2006-12-08 02:39:19 -0800 | [diff] [blame] | 4260 | static struct stliport *stli_getport(unsigned int brdnr, unsigned int panelnr, |
| 4261 | unsigned int portnr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4262 | { |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 4263 | struct stlibrd *brdp; |
Jiri Slaby | 1328d73 | 2006-12-08 02:39:19 -0800 | [diff] [blame] | 4264 | unsigned int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4265 | |
Jiri Slaby | 1328d73 | 2006-12-08 02:39:19 -0800 | [diff] [blame] | 4266 | if (brdnr >= STL_MAXBRDS) |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4267 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4268 | brdp = stli_brds[brdnr]; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4269 | if (brdp == NULL) |
| 4270 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4271 | for (i = 0; (i < panelnr); i++) |
| 4272 | portnr += brdp->panels[i]; |
Jiri Slaby | 1328d73 | 2006-12-08 02:39:19 -0800 | [diff] [blame] | 4273 | if (portnr >= brdp->nrports) |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4274 | return NULL; |
| 4275 | return brdp->ports[portnr]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4276 | } |
| 4277 | |
| 4278 | /*****************************************************************************/ |
| 4279 | |
| 4280 | /* |
| 4281 | * Return the port stats structure to user app. A NULL port struct |
| 4282 | * pointer passed in means that we need to find out from the app |
| 4283 | * what port to get stats for (used through board control device). |
| 4284 | */ |
| 4285 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 4286 | static int stli_portcmdstats(struct stliport *portp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4287 | { |
| 4288 | unsigned long flags; |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 4289 | struct stlibrd *brdp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4290 | int rc; |
| 4291 | |
| 4292 | memset(&stli_comstats, 0, sizeof(comstats_t)); |
| 4293 | |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4294 | if (portp == NULL) |
| 4295 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4296 | brdp = stli_brds[portp->brdnr]; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4297 | if (brdp == NULL) |
| 4298 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4299 | |
| 4300 | if (brdp->state & BST_STARTED) { |
| 4301 | if ((rc = stli_cmdwait(brdp, portp, A_GETSTATS, |
| 4302 | &stli_cdkstats, sizeof(asystats_t), 1)) < 0) |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4303 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4304 | } else { |
| 4305 | memset(&stli_cdkstats, 0, sizeof(asystats_t)); |
| 4306 | } |
| 4307 | |
| 4308 | stli_comstats.brd = portp->brdnr; |
| 4309 | stli_comstats.panel = portp->panelnr; |
| 4310 | stli_comstats.port = portp->portnr; |
| 4311 | stli_comstats.state = portp->state; |
| 4312 | stli_comstats.flags = portp->flags; |
| 4313 | |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4314 | spin_lock_irqsave(&brd_lock, flags); |
| 4315 | if (portp->tty != NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4316 | if (portp->tty->driver_data == portp) { |
| 4317 | stli_comstats.ttystate = portp->tty->flags; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4318 | stli_comstats.rxbuffered = -1; |
| 4319 | if (portp->tty->termios != NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4320 | stli_comstats.cflags = portp->tty->termios->c_cflag; |
| 4321 | stli_comstats.iflags = portp->tty->termios->c_iflag; |
| 4322 | stli_comstats.oflags = portp->tty->termios->c_oflag; |
| 4323 | stli_comstats.lflags = portp->tty->termios->c_lflag; |
| 4324 | } |
| 4325 | } |
| 4326 | } |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4327 | spin_unlock_irqrestore(&brd_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4328 | |
| 4329 | stli_comstats.txtotal = stli_cdkstats.txchars; |
| 4330 | stli_comstats.rxtotal = stli_cdkstats.rxchars + stli_cdkstats.ringover; |
| 4331 | stli_comstats.txbuffered = stli_cdkstats.txringq; |
| 4332 | stli_comstats.rxbuffered += stli_cdkstats.rxringq; |
| 4333 | stli_comstats.rxoverrun = stli_cdkstats.overruns; |
| 4334 | stli_comstats.rxparity = stli_cdkstats.parity; |
| 4335 | stli_comstats.rxframing = stli_cdkstats.framing; |
| 4336 | stli_comstats.rxlost = stli_cdkstats.ringover; |
| 4337 | stli_comstats.rxbreaks = stli_cdkstats.rxbreaks; |
| 4338 | stli_comstats.txbreaks = stli_cdkstats.txbreaks; |
| 4339 | stli_comstats.txxon = stli_cdkstats.txstart; |
| 4340 | stli_comstats.txxoff = stli_cdkstats.txstop; |
| 4341 | stli_comstats.rxxon = stli_cdkstats.rxstart; |
| 4342 | stli_comstats.rxxoff = stli_cdkstats.rxstop; |
| 4343 | stli_comstats.rxrtsoff = stli_cdkstats.rtscnt / 2; |
| 4344 | stli_comstats.rxrtson = stli_cdkstats.rtscnt - stli_comstats.rxrtsoff; |
| 4345 | stli_comstats.modem = stli_cdkstats.dcdcnt; |
| 4346 | stli_comstats.hwid = stli_cdkstats.hwid; |
| 4347 | stli_comstats.signals = stli_mktiocm(stli_cdkstats.signals); |
| 4348 | |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4349 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4350 | } |
| 4351 | |
| 4352 | /*****************************************************************************/ |
| 4353 | |
| 4354 | /* |
| 4355 | * Return the port stats structure to user app. A NULL port struct |
| 4356 | * pointer passed in means that we need to find out from the app |
| 4357 | * what port to get stats for (used through board control device). |
| 4358 | */ |
| 4359 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 4360 | static int stli_getportstats(struct stliport *portp, comstats_t __user *cp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4361 | { |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 4362 | struct stlibrd *brdp; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4363 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4364 | |
| 4365 | if (!portp) { |
| 4366 | if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t))) |
| 4367 | return -EFAULT; |
| 4368 | portp = stli_getport(stli_comstats.brd, stli_comstats.panel, |
| 4369 | stli_comstats.port); |
| 4370 | if (!portp) |
| 4371 | return -ENODEV; |
| 4372 | } |
| 4373 | |
| 4374 | brdp = stli_brds[portp->brdnr]; |
| 4375 | if (!brdp) |
| 4376 | return -ENODEV; |
| 4377 | |
| 4378 | if ((rc = stli_portcmdstats(portp)) < 0) |
| 4379 | return rc; |
| 4380 | |
| 4381 | return copy_to_user(cp, &stli_comstats, sizeof(comstats_t)) ? |
| 4382 | -EFAULT : 0; |
| 4383 | } |
| 4384 | |
| 4385 | /*****************************************************************************/ |
| 4386 | |
| 4387 | /* |
| 4388 | * Clear the port stats structure. We also return it zeroed out... |
| 4389 | */ |
| 4390 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 4391 | static int stli_clrportstats(struct stliport *portp, comstats_t __user *cp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4392 | { |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 4393 | struct stlibrd *brdp; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4394 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4395 | |
| 4396 | if (!portp) { |
| 4397 | if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t))) |
| 4398 | return -EFAULT; |
| 4399 | portp = stli_getport(stli_comstats.brd, stli_comstats.panel, |
| 4400 | stli_comstats.port); |
| 4401 | if (!portp) |
| 4402 | return -ENODEV; |
| 4403 | } |
| 4404 | |
| 4405 | brdp = stli_brds[portp->brdnr]; |
| 4406 | if (!brdp) |
| 4407 | return -ENODEV; |
| 4408 | |
| 4409 | if (brdp->state & BST_STARTED) { |
| 4410 | if ((rc = stli_cmdwait(brdp, portp, A_CLEARSTATS, NULL, 0, 0)) < 0) |
| 4411 | return rc; |
| 4412 | } |
| 4413 | |
| 4414 | memset(&stli_comstats, 0, sizeof(comstats_t)); |
| 4415 | stli_comstats.brd = portp->brdnr; |
| 4416 | stli_comstats.panel = portp->panelnr; |
| 4417 | stli_comstats.port = portp->portnr; |
| 4418 | |
| 4419 | if (copy_to_user(cp, &stli_comstats, sizeof(comstats_t))) |
| 4420 | return -EFAULT; |
| 4421 | return 0; |
| 4422 | } |
| 4423 | |
| 4424 | /*****************************************************************************/ |
| 4425 | |
| 4426 | /* |
| 4427 | * Return the entire driver ports structure to a user app. |
| 4428 | */ |
| 4429 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 4430 | static int stli_getportstruct(struct stliport __user *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4431 | { |
Jiri Slaby | 1328d73 | 2006-12-08 02:39:19 -0800 | [diff] [blame] | 4432 | struct stliport stli_dummyport; |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 4433 | struct stliport *portp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4434 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 4435 | if (copy_from_user(&stli_dummyport, arg, sizeof(struct stliport))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4436 | return -EFAULT; |
| 4437 | portp = stli_getport(stli_dummyport.brdnr, stli_dummyport.panelnr, |
| 4438 | stli_dummyport.portnr); |
| 4439 | if (!portp) |
| 4440 | return -ENODEV; |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 4441 | if (copy_to_user(arg, portp, sizeof(struct stliport))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4442 | return -EFAULT; |
| 4443 | return 0; |
| 4444 | } |
| 4445 | |
| 4446 | /*****************************************************************************/ |
| 4447 | |
| 4448 | /* |
| 4449 | * Return the entire driver board structure to a user app. |
| 4450 | */ |
| 4451 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 4452 | static int stli_getbrdstruct(struct stlibrd __user *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4453 | { |
Jiri Slaby | 1328d73 | 2006-12-08 02:39:19 -0800 | [diff] [blame] | 4454 | struct stlibrd stli_dummybrd; |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 4455 | struct stlibrd *brdp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4456 | |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 4457 | if (copy_from_user(&stli_dummybrd, arg, sizeof(struct stlibrd))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4458 | return -EFAULT; |
Jiri Slaby | 1328d73 | 2006-12-08 02:39:19 -0800 | [diff] [blame] | 4459 | if (stli_dummybrd.brdnr >= STL_MAXBRDS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4460 | return -ENODEV; |
| 4461 | brdp = stli_brds[stli_dummybrd.brdnr]; |
| 4462 | if (!brdp) |
| 4463 | return -ENODEV; |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 4464 | if (copy_to_user(arg, brdp, sizeof(struct stlibrd))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4465 | return -EFAULT; |
| 4466 | return 0; |
| 4467 | } |
| 4468 | |
| 4469 | /*****************************************************************************/ |
| 4470 | |
| 4471 | /* |
| 4472 | * The "staliomem" device is also required to do some special operations on |
| 4473 | * the board. We need to be able to send an interrupt to the board, |
| 4474 | * reset it, and start/stop it. |
| 4475 | */ |
| 4476 | |
| 4477 | static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg) |
| 4478 | { |
Jiri Slaby | 1f8ec43 | 2006-12-08 02:39:18 -0800 | [diff] [blame] | 4479 | struct stlibrd *brdp; |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4480 | int brdnr, rc, done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4481 | void __user *argp = (void __user *)arg; |
| 4482 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4483 | /* |
| 4484 | * First up handle the board independent ioctls. |
| 4485 | */ |
| 4486 | done = 0; |
| 4487 | rc = 0; |
| 4488 | |
| 4489 | switch (cmd) { |
| 4490 | case COM_GETPORTSTATS: |
| 4491 | rc = stli_getportstats(NULL, argp); |
| 4492 | done++; |
| 4493 | break; |
| 4494 | case COM_CLRPORTSTATS: |
| 4495 | rc = stli_clrportstats(NULL, argp); |
| 4496 | done++; |
| 4497 | break; |
| 4498 | case COM_GETBRDSTATS: |
| 4499 | rc = stli_getbrdstats(argp); |
| 4500 | done++; |
| 4501 | break; |
| 4502 | case COM_READPORT: |
| 4503 | rc = stli_getportstruct(argp); |
| 4504 | done++; |
| 4505 | break; |
| 4506 | case COM_READBOARD: |
| 4507 | rc = stli_getbrdstruct(argp); |
| 4508 | done++; |
| 4509 | break; |
| 4510 | } |
| 4511 | |
| 4512 | if (done) |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4513 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4514 | |
| 4515 | /* |
| 4516 | * Now handle the board specific ioctls. These all depend on the |
| 4517 | * minor number of the device they were called from. |
| 4518 | */ |
| 4519 | brdnr = iminor(ip); |
| 4520 | if (brdnr >= STL_MAXBRDS) |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4521 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4522 | brdp = stli_brds[brdnr]; |
| 4523 | if (!brdp) |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4524 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4525 | if (brdp->state == 0) |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4526 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4527 | |
| 4528 | switch (cmd) { |
| 4529 | case STL_BINTR: |
| 4530 | EBRDINTR(brdp); |
| 4531 | break; |
| 4532 | case STL_BSTART: |
| 4533 | rc = stli_startbrd(brdp); |
| 4534 | break; |
| 4535 | case STL_BSTOP: |
| 4536 | brdp->state &= ~BST_STARTED; |
| 4537 | break; |
| 4538 | case STL_BRESET: |
| 4539 | brdp->state &= ~BST_STARTED; |
| 4540 | EBRDRESET(brdp); |
| 4541 | if (stli_shared == 0) { |
| 4542 | if (brdp->reenable != NULL) |
| 4543 | (* brdp->reenable)(brdp); |
| 4544 | } |
| 4545 | break; |
| 4546 | default: |
| 4547 | rc = -ENOIOCTLCMD; |
| 4548 | break; |
| 4549 | } |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4550 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4551 | } |
| 4552 | |
Jeff Dike | b68e31d | 2006-10-02 02:17:18 -0700 | [diff] [blame] | 4553 | static const struct tty_operations stli_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4554 | .open = stli_open, |
| 4555 | .close = stli_close, |
| 4556 | .write = stli_write, |
| 4557 | .put_char = stli_putchar, |
| 4558 | .flush_chars = stli_flushchars, |
| 4559 | .write_room = stli_writeroom, |
| 4560 | .chars_in_buffer = stli_charsinbuffer, |
| 4561 | .ioctl = stli_ioctl, |
| 4562 | .set_termios = stli_settermios, |
| 4563 | .throttle = stli_throttle, |
| 4564 | .unthrottle = stli_unthrottle, |
| 4565 | .stop = stli_stop, |
| 4566 | .start = stli_start, |
| 4567 | .hangup = stli_hangup, |
| 4568 | .flush_buffer = stli_flushbuffer, |
| 4569 | .break_ctl = stli_breakctl, |
| 4570 | .wait_until_sent = stli_waituntilsent, |
| 4571 | .send_xchar = stli_sendxchar, |
| 4572 | .read_proc = stli_readproc, |
| 4573 | .tiocmget = stli_tiocmget, |
| 4574 | .tiocmset = stli_tiocmset, |
| 4575 | }; |
| 4576 | |
| 4577 | /*****************************************************************************/ |
| 4578 | |
Adrian Bunk | 672b271 | 2006-06-30 01:55:30 -0700 | [diff] [blame] | 4579 | static int __init stli_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4580 | { |
| 4581 | int i; |
| 4582 | printk(KERN_INFO "%s: version %s\n", stli_drvtitle, stli_drvversion); |
| 4583 | |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4584 | spin_lock_init(&stli_lock); |
| 4585 | spin_lock_init(&brd_lock); |
| 4586 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4587 | stli_initbrds(); |
| 4588 | |
| 4589 | stli_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS); |
| 4590 | if (!stli_serial) |
| 4591 | return -ENOMEM; |
| 4592 | |
| 4593 | /* |
| 4594 | * Allocate a temporary write buffer. |
| 4595 | */ |
Tobias Klauser | b0b4ed7 | 2006-03-31 02:30:56 -0800 | [diff] [blame] | 4596 | stli_txcookbuf = kmalloc(STLI_TXBUFSIZE, GFP_KERNEL); |
| 4597 | if (!stli_txcookbuf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4598 | printk(KERN_ERR "STALLION: failed to allocate memory " |
| 4599 | "(size=%d)\n", STLI_TXBUFSIZE); |
| 4600 | |
| 4601 | /* |
| 4602 | * Set up a character driver for the shared memory region. We need this |
| 4603 | * to down load the slave code image. Also it is a useful debugging tool. |
| 4604 | */ |
| 4605 | if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stli_fsiomem)) |
| 4606 | printk(KERN_ERR "STALLION: failed to register serial memory " |
| 4607 | "device\n"); |
| 4608 | |
gregkh@suse.de | ca8eca6 | 2005-03-23 09:53:09 -0800 | [diff] [blame] | 4609 | istallion_class = class_create(THIS_MODULE, "staliomem"); |
Greg Kroah-Hartman | 7c69ef7 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 4610 | for (i = 0; i < 4; i++) |
Greg Kroah-Hartman | 53f4654 | 2005-10-27 22:25:43 -0700 | [diff] [blame] | 4611 | class_device_create(istallion_class, NULL, |
| 4612 | MKDEV(STL_SIOMEMMAJOR, i), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4613 | NULL, "staliomem%d", i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4614 | |
| 4615 | /* |
| 4616 | * Set up the tty driver structure and register us as a driver. |
| 4617 | */ |
| 4618 | stli_serial->owner = THIS_MODULE; |
| 4619 | stli_serial->driver_name = stli_drvname; |
| 4620 | stli_serial->name = stli_serialname; |
| 4621 | stli_serial->major = STL_SERIALMAJOR; |
| 4622 | stli_serial->minor_start = 0; |
| 4623 | stli_serial->type = TTY_DRIVER_TYPE_SERIAL; |
| 4624 | stli_serial->subtype = SERIAL_TYPE_NORMAL; |
| 4625 | stli_serial->init_termios = stli_deftermios; |
| 4626 | stli_serial->flags = TTY_DRIVER_REAL_RAW; |
| 4627 | tty_set_operations(stli_serial, &stli_ops); |
| 4628 | |
| 4629 | if (tty_register_driver(stli_serial)) { |
| 4630 | put_tty_driver(stli_serial); |
| 4631 | printk(KERN_ERR "STALLION: failed to register serial driver\n"); |
| 4632 | return -EBUSY; |
| 4633 | } |
Alan Cox | 4ac4360 | 2006-06-28 04:26:52 -0700 | [diff] [blame] | 4634 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4635 | } |
| 4636 | |
| 4637 | /*****************************************************************************/ |