Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* sx.c -- driver for the Specialix SX series cards. |
| 2 | * |
| 3 | * This driver will also support the older SI, and XIO cards. |
| 4 | * |
| 5 | * |
| 6 | * (C) 1998 - 2004 R.E.Wolff@BitWizard.nl |
| 7 | * |
| 8 | * Simon Allen (simonallen@cix.compulink.co.uk) wrote a previous |
| 9 | * version of this driver. Some fragments may have been copied. (none |
| 10 | * yet :-) |
| 11 | * |
| 12 | * Specialix pays for the development and support of this driver. |
| 13 | * Please DO contact support@specialix.co.uk if you require |
| 14 | * support. But please read the documentation (sx.txt) first. |
| 15 | * |
| 16 | * |
| 17 | * |
| 18 | * This program is free software; you can redistribute it and/or |
| 19 | * modify it under the terms of the GNU General Public License as |
| 20 | * published by the Free Software Foundation; either version 2 of |
| 21 | * the License, or (at your option) any later version. |
| 22 | * |
| 23 | * This program is distributed in the hope that it will be |
| 24 | * useful, but WITHOUT ANY WARRANTY; without even the implied |
| 25 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 26 | * PURPOSE. See the GNU General Public License for more details. |
| 27 | * |
| 28 | * You should have received a copy of the GNU General Public |
| 29 | * License along with this program; if not, write to the Free |
| 30 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, |
| 31 | * USA. |
| 32 | * |
| 33 | * Revision history: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | * Revision 1.33 2000/03/09 10:00:00 pvdl,wolff |
| 35 | * - Fixed module and port counting |
| 36 | * - Fixed signal handling |
| 37 | * - Fixed an Ooops |
| 38 | * |
| 39 | * Revision 1.32 2000/03/07 09:00:00 wolff,pvdl |
| 40 | * - Fixed some sx_dprintk typos |
| 41 | * - added detection for an invalid board/module configuration |
| 42 | * |
| 43 | * Revision 1.31 2000/03/06 12:00:00 wolff,pvdl |
| 44 | * - Added support for EISA |
| 45 | * |
| 46 | * Revision 1.30 2000/01/21 17:43:06 wolff |
| 47 | * - Added support for SX+ |
| 48 | * |
| 49 | * Revision 1.26 1999/08/05 15:22:14 wolff |
| 50 | * - Port to 2.3.x |
| 51 | * - Reformatted to Linus' liking. |
| 52 | * |
| 53 | * Revision 1.25 1999/07/30 14:24:08 wolff |
| 54 | * Had accidentally left "gs_debug" set to "-1" instead of "off" (=0). |
| 55 | * |
| 56 | * Revision 1.24 1999/07/28 09:41:52 wolff |
| 57 | * - I noticed the remark about use-count straying in sx.txt. I checked |
| 58 | * sx_open, and found a few places where that could happen. I hope it's |
| 59 | * fixed now. |
| 60 | * |
| 61 | * Revision 1.23 1999/07/28 08:56:06 wolff |
| 62 | * - Fixed crash when sx_firmware run twice. |
| 63 | * - Added sx_slowpoll as a module parameter (I guess nobody really wanted |
| 64 | * to change it from the default... ) |
| 65 | * - Fixed a stupid editing problem I introduced in 1.22. |
| 66 | * - Fixed dropping characters on a termios change. |
| 67 | * |
| 68 | * Revision 1.22 1999/07/26 21:01:43 wolff |
| 69 | * Russell Brown noticed that I had overlooked 4 out of six modem control |
| 70 | * signals in sx_getsignals. Ooops. |
| 71 | * |
| 72 | * Revision 1.21 1999/07/23 09:11:33 wolff |
| 73 | * I forgot to free dynamically allocated memory when the driver is unloaded. |
| 74 | * |
| 75 | * Revision 1.20 1999/07/20 06:25:26 wolff |
| 76 | * The "closing wait" wasn't honoured. Thanks to James Griffiths for |
| 77 | * reporting this. |
| 78 | * |
| 79 | * Revision 1.19 1999/07/11 08:59:59 wolff |
| 80 | * Fixed an oops in close, when an open was pending. Changed the memtest |
| 81 | * a bit. Should also test the board in word-mode, however my card fails the |
| 82 | * memtest then. I still have to figure out what is wrong... |
| 83 | * |
| 84 | * Revision 1.18 1999/06/10 09:38:42 wolff |
| 85 | * Changed the format of the firmware revision from %04x to %x.%02x . |
| 86 | * |
| 87 | * Revision 1.17 1999/06/04 09:44:35 wolff |
| 88 | * fixed problem: reference to pci stuff when config_pci was off... |
| 89 | * Thanks to Jorge Novo for noticing this. |
| 90 | * |
| 91 | * Revision 1.16 1999/06/02 08:30:15 wolff |
| 92 | * added/removed the workaround for the DCD bug in the Firmware. |
| 93 | * A bit more debugging code to locate that... |
| 94 | * |
| 95 | * Revision 1.15 1999/06/01 11:35:30 wolff |
| 96 | * when DCD is left low (floating?), on TA's the firmware first tells us |
| 97 | * that DCD is high, but after a short while suddenly comes to the |
| 98 | * conclusion that it is low. All this would be fine, if it weren't that |
| 99 | * Unix requires us to send a "hangup" signal in that case. This usually |
| 100 | * all happens BEFORE the program has had a chance to ioctl the device |
| 101 | * into clocal mode.. |
| 102 | * |
| 103 | * Revision 1.14 1999/05/25 11:18:59 wolff |
| 104 | * Added PCI-fix. |
| 105 | * Added checks for return code of sx_sendcommand. |
| 106 | * Don't issue "reconfig" if port isn't open yet. (bit us on TA modules...) |
| 107 | * |
| 108 | * Revision 1.13 1999/04/29 15:18:01 wolff |
| 109 | * Fixed an "oops" that showed on SuSE 6.0 systems. |
| 110 | * Activate DTR again after stty 0. |
| 111 | * |
| 112 | * Revision 1.12 1999/04/29 07:49:52 wolff |
| 113 | * Improved "stty 0" handling a bit. (used to change baud to 9600 assuming |
| 114 | * the connection would be dropped anyway. That is not always the case, |
| 115 | * and confuses people). |
| 116 | * Told the card to always monitor the modem signals. |
| 117 | * Added support for dynamic gs_debug adjustments. |
| 118 | * Now tells the rest of the system the number of ports. |
| 119 | * |
| 120 | * Revision 1.11 1999/04/24 11:11:30 wolff |
| 121 | * Fixed two stupid typos in the memory test. |
| 122 | * |
| 123 | * Revision 1.10 1999/04/24 10:53:39 wolff |
| 124 | * Added some of Christian's suggestions. |
| 125 | * Fixed an HW_COOK_IN bug (ISIG was not in I_OTHER. We used to trust the |
| 126 | * card to send the signal to the process.....) |
| 127 | * |
| 128 | * Revision 1.9 1999/04/23 07:26:38 wolff |
| 129 | * Included Christian Lademann's 2.0 compile-warning fixes and interrupt |
| 130 | * assignment redesign. |
| 131 | * Cleanup of some other stuff. |
| 132 | * |
| 133 | * Revision 1.8 1999/04/16 13:05:30 wolff |
| 134 | * fixed a DCD change unnoticed bug. |
| 135 | * |
| 136 | * Revision 1.7 1999/04/14 22:19:51 wolff |
| 137 | * Fixed typo that showed up in 2.0.x builds (get_user instead of Get_user!) |
| 138 | * |
| 139 | * Revision 1.6 1999/04/13 18:40:20 wolff |
| 140 | * changed misc-minor to 161, as assigned by HPA. |
| 141 | * |
| 142 | * Revision 1.5 1999/04/13 15:12:25 wolff |
| 143 | * Fixed use-count leak when "hangup" occurred. |
| 144 | * Added workaround for a stupid-PCIBIOS bug. |
| 145 | * |
| 146 | * |
| 147 | * Revision 1.4 1999/04/01 22:47:40 wolff |
| 148 | * Fixed < 1M linux-2.0 problem. |
| 149 | * (vremap isn't compatible with ioremap in that case) |
| 150 | * |
| 151 | * Revision 1.3 1999/03/31 13:45:45 wolff |
| 152 | * Firmware loading is now done through a separate IOCTL. |
| 153 | * |
| 154 | * Revision 1.2 1999/03/28 12:22:29 wolff |
| 155 | * rcs cleanup |
| 156 | * |
| 157 | * Revision 1.1 1999/03/28 12:10:34 wolff |
| 158 | * Readying for release on 2.0.x (sorry David, 1.01 becomes 1.1 for RCS). |
| 159 | * |
| 160 | * Revision 0.12 1999/03/28 09:20:10 wolff |
| 161 | * Fixed problem in 0.11, continueing cleanup. |
| 162 | * |
| 163 | * Revision 0.11 1999/03/28 08:46:44 wolff |
| 164 | * cleanup. Not good. |
| 165 | * |
| 166 | * Revision 0.10 1999/03/28 08:09:43 wolff |
| 167 | * Fixed loosing characters on close. |
| 168 | * |
| 169 | * Revision 0.9 1999/03/21 22:52:01 wolff |
| 170 | * Ported back to 2.2.... (minor things) |
| 171 | * |
| 172 | * Revision 0.8 1999/03/21 22:40:33 wolff |
| 173 | * Port to 2.0 |
| 174 | * |
| 175 | * Revision 0.7 1999/03/21 19:06:34 wolff |
| 176 | * Fixed hangup processing. |
| 177 | * |
| 178 | * Revision 0.6 1999/02/05 08:45:14 wolff |
| 179 | * fixed real_raw problems. Inclusion into kernel imminent. |
| 180 | * |
| 181 | * Revision 0.5 1998/12/21 23:51:06 wolff |
| 182 | * Snatched a nasty bug: sx_transmit_chars was getting re-entered, and it |
| 183 | * shouldn't have. THATs why I want to have transmit interrupts even when |
| 184 | * the buffer is empty. |
| 185 | * |
| 186 | * Revision 0.4 1998/12/17 09:34:46 wolff |
| 187 | * PPP works. ioctl works. Basically works! |
| 188 | * |
| 189 | * Revision 0.3 1998/12/15 13:05:18 wolff |
| 190 | * It works! Wow! Gotta start implementing IOCTL and stuff.... |
| 191 | * |
| 192 | * Revision 0.2 1998/12/01 08:33:53 wolff |
| 193 | * moved over to 2.1.130 |
| 194 | * |
| 195 | * Revision 0.1 1998/11/03 21:23:51 wolff |
| 196 | * Initial revision. Detects SX card. |
| 197 | * |
| 198 | * */ |
| 199 | |
Jiri Slaby | 11c8387 | 2006-12-08 02:38:56 -0800 | [diff] [blame] | 200 | #define SX_VERSION 1.33 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | #include <linux/kdev_t.h> |
| 204 | #include <linux/kernel.h> |
| 205 | #include <linux/sched.h> |
| 206 | #include <linux/ioport.h> |
| 207 | #include <linux/interrupt.h> |
| 208 | #include <linux/errno.h> |
| 209 | #include <linux/tty.h> |
| 210 | #include <linux/tty_flip.h> |
| 211 | #include <linux/mm.h> |
| 212 | #include <linux/serial.h> |
| 213 | #include <linux/fcntl.h> |
| 214 | #include <linux/major.h> |
| 215 | #include <linux/delay.h> |
Jiri Slaby | 18f813e | 2006-12-08 02:39:01 -0800 | [diff] [blame] | 216 | #include <linux/eisa.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | #include <linux/pci.h> |
| 218 | #include <linux/slab.h> |
| 219 | #include <linux/init.h> |
| 220 | #include <linux/miscdevice.h> |
| 221 | #include <linux/bitops.h> |
| 222 | |
| 223 | #include <asm/io.h> |
| 224 | #include <asm/uaccess.h> |
| 225 | |
| 226 | /* The 3.0.0 version of sxboards/sxwindow.h uses BYTE and WORD.... */ |
| 227 | #define BYTE u8 |
| 228 | #define WORD u16 |
| 229 | |
| 230 | /* .... but the 3.0.4 version uses _u8 and _u16. */ |
| 231 | #define _u8 u8 |
| 232 | #define _u16 u16 |
| 233 | |
| 234 | #include "sxboards.h" |
| 235 | #include "sxwindow.h" |
| 236 | |
| 237 | #include <linux/generic_serial.h> |
| 238 | #include "sx.h" |
| 239 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | /* I don't think that this driver can handle more than 256 ports on |
| 241 | one machine. You'll have to increase the number of boards in sx.h |
| 242 | if you want more than 4 boards. */ |
| 243 | |
| 244 | #ifndef PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8 |
| 245 | #define PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8 0x2000 |
| 246 | #endif |
| 247 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | /* Configurable options: |
| 249 | (Don't be too sure that it'll work if you toggle them) */ |
| 250 | |
| 251 | /* Am I paranoid or not ? ;-) */ |
| 252 | #undef SX_PARANOIA_CHECK |
| 253 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | /* 20 -> 2000 per second. The card should rate-limit interrupts at 100 |
| 255 | Hz, but it is user configurable. I don't recommend going above 1000 |
| 256 | Hz. The interrupt ratelimit might trigger if the interrupt is |
| 257 | shared with a very active other device. */ |
| 258 | #define IRQ_RATE_LIMIT 20 |
| 259 | |
| 260 | /* Sharing interrupts is possible now. If the other device wants more |
| 261 | than 2000 interrupts per second, we'd gracefully decline further |
| 262 | interrupts. That's not what we want. On the other hand, if the |
| 263 | other device interrupts 2000 times a second, don't use the SX |
| 264 | interrupt. Use polling. */ |
| 265 | #undef IRQ_RATE_LIMIT |
| 266 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | #if 0 |
| 268 | /* Not implemented */ |
| 269 | /* |
| 270 | * The following defines are mostly for testing purposes. But if you need |
| 271 | * some nice reporting in your syslog, you can define them also. |
| 272 | */ |
| 273 | #define SX_REPORT_FIFO |
| 274 | #define SX_REPORT_OVERRUN |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 275 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | |
| 277 | /* Function prototypes */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 278 | static void sx_disable_tx_interrupts(void *ptr); |
| 279 | static void sx_enable_tx_interrupts(void *ptr); |
| 280 | static void sx_disable_rx_interrupts(void *ptr); |
| 281 | static void sx_enable_rx_interrupts(void *ptr); |
Alan Cox | 31f3593 | 2009-01-02 13:45:05 +0000 | [diff] [blame] | 282 | static int sx_carrier_raised(struct tty_port *port); |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 283 | static void sx_shutdown_port(void *ptr); |
| 284 | static int sx_set_real_termios(void *ptr); |
| 285 | static void sx_close(void *ptr); |
| 286 | static int sx_chars_in_buffer(void *ptr); |
| 287 | static int sx_init_board(struct sx_board *board); |
| 288 | static int sx_init_portstructs(int nboards, int nports); |
Alan Cox | 11af747 | 2008-07-25 01:48:15 -0700 | [diff] [blame] | 289 | static long sx_fw_ioctl(struct file *filp, unsigned int cmd, |
| 290 | unsigned long arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | static int sx_init_drivers(void); |
| 292 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | static struct tty_driver *sx_driver; |
| 294 | |
Jiri Slaby | 42f6384 | 2006-12-08 02:39:03 -0800 | [diff] [blame] | 295 | static DEFINE_MUTEX(sx_boards_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | static struct sx_board boards[SX_NBOARDS]; |
| 297 | static struct sx_port *sx_ports; |
| 298 | static int sx_initialized; |
| 299 | static int sx_nports; |
| 300 | static int sx_debug; |
| 301 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | /* You can have the driver poll your card. |
| 303 | - Set sx_poll to 1 to poll every timer tick (10ms on Intel). |
| 304 | This is used when the card cannot use an interrupt for some reason. |
| 305 | |
| 306 | - set sx_slowpoll to 100 to do an extra poll once a second (on Intel). If |
| 307 | the driver misses an interrupt (report this if it DOES happen to you!) |
| 308 | everything will continue to work.... |
| 309 | */ |
| 310 | static int sx_poll = 1; |
| 311 | static int sx_slowpoll; |
| 312 | |
| 313 | /* The card limits the number of interrupts per second. |
| 314 | At 115k2 "100" should be sufficient. |
| 315 | If you're using higher baudrates, you can increase this... |
| 316 | */ |
| 317 | |
| 318 | static int sx_maxints = 100; |
| 319 | |
Jiri Slaby | 927a6f9 | 2006-12-08 02:39:02 -0800 | [diff] [blame] | 320 | #ifdef CONFIG_ISA |
| 321 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | /* These are the only open spaces in my computer. Yours may have more |
| 323 | or less.... -- REW |
| 324 | duh: Card at 0xa0000 is possible on HP Netserver?? -- pvdl |
| 325 | */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 326 | static int sx_probe_addrs[] = { |
| 327 | 0xc0000, 0xd0000, 0xe0000, |
| 328 | 0xc8000, 0xd8000, 0xe8000 |
| 329 | }; |
| 330 | static int si_probe_addrs[] = { |
| 331 | 0xc0000, 0xd0000, 0xe0000, |
| 332 | 0xc8000, 0xd8000, 0xe8000, 0xa0000 |
| 333 | }; |
| 334 | static int si1_probe_addrs[] = { |
| 335 | 0xd0000 |
| 336 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | |
Tobias Klauser | fe97107 | 2006-01-09 20:54:02 -0800 | [diff] [blame] | 338 | #define NR_SX_ADDRS ARRAY_SIZE(sx_probe_addrs) |
| 339 | #define NR_SI_ADDRS ARRAY_SIZE(si_probe_addrs) |
| 340 | #define NR_SI1_ADDRS ARRAY_SIZE(si1_probe_addrs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | |
Jiri Slaby | 927a6f9 | 2006-12-08 02:39:02 -0800 | [diff] [blame] | 342 | module_param_array(sx_probe_addrs, int, NULL, 0); |
| 343 | module_param_array(si_probe_addrs, int, NULL, 0); |
| 344 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | |
| 346 | /* Set the mask to all-ones. This alas, only supports 32 interrupts. |
| 347 | Some architectures may need more. */ |
| 348 | static int sx_irqmask = -1; |
| 349 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | module_param(sx_poll, int, 0); |
| 351 | module_param(sx_slowpoll, int, 0); |
| 352 | module_param(sx_maxints, int, 0); |
| 353 | module_param(sx_debug, int, 0); |
| 354 | module_param(sx_irqmask, int, 0); |
| 355 | |
| 356 | MODULE_LICENSE("GPL"); |
| 357 | |
| 358 | static struct real_driver sx_real_driver = { |
| 359 | sx_disable_tx_interrupts, |
| 360 | sx_enable_tx_interrupts, |
| 361 | sx_disable_rx_interrupts, |
| 362 | sx_enable_rx_interrupts, |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 363 | sx_shutdown_port, |
| 364 | sx_set_real_termios, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | sx_chars_in_buffer, |
| 366 | sx_close, |
| 367 | }; |
| 368 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | /* |
| 370 | This driver can spew a whole lot of debugging output at you. If you |
| 371 | need maximum performance, you should disable the DEBUG define. To |
| 372 | aid in debugging in the field, I'm leaving the compile-time debug |
| 373 | features enabled, and disable them "runtime". That allows me to |
| 374 | instruct people with problems to enable debugging without requiring |
| 375 | them to recompile... |
| 376 | */ |
| 377 | #define DEBUG |
| 378 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | #ifdef DEBUG |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 380 | #define sx_dprintk(f, str...) if (sx_debug & f) printk (str) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | #else |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 382 | #define sx_dprintk(f, str...) /* nothing */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | #endif |
| 384 | |
Harvey Harrison | bf9d892 | 2008-04-30 00:55:10 -0700 | [diff] [blame] | 385 | #define func_enter() sx_dprintk(SX_DEBUG_FLOW, "sx: enter %s\n",__func__) |
| 386 | #define func_exit() sx_dprintk(SX_DEBUG_FLOW, "sx: exit %s\n",__func__) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 388 | #define func_enter2() sx_dprintk(SX_DEBUG_FLOW, "sx: enter %s (port %d)\n", \ |
Harvey Harrison | bf9d892 | 2008-04-30 00:55:10 -0700 | [diff] [blame] | 389 | __func__, port->line) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | |
| 391 | /* |
| 392 | * Firmware loader driver specific routines |
| 393 | * |
| 394 | */ |
| 395 | |
Arjan van de Ven | 62322d2 | 2006-07-03 00:24:21 -0700 | [diff] [blame] | 396 | static const struct file_operations sx_fw_fops = { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 397 | .owner = THIS_MODULE, |
Alan Cox | 11af747 | 2008-07-25 01:48:15 -0700 | [diff] [blame] | 398 | .unlocked_ioctl = sx_fw_ioctl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | }; |
| 400 | |
| 401 | static struct miscdevice sx_fw_device = { |
| 402 | SXCTL_MISC_MINOR, "sxctl", &sx_fw_fops |
| 403 | }; |
| 404 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | #ifdef SX_PARANOIA_CHECK |
| 406 | |
| 407 | /* This doesn't work. Who's paranoid around here? Not me! */ |
| 408 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 409 | static inline int sx_paranoia_check(struct sx_port const *port, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | char *name, const char *routine) |
| 411 | { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 412 | static const char *badmagic = KERN_ERR "sx: Warning: bad sx port magic " |
| 413 | "number for device %s in %s\n"; |
| 414 | static const char *badinfo = KERN_ERR "sx: Warning: null sx port for " |
| 415 | "device %s in %s\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | if (!port) { |
| 418 | printk(badinfo, name, routine); |
| 419 | return 1; |
| 420 | } |
| 421 | if (port->magic != SX_MAGIC) { |
| 422 | printk(badmagic, name, routine); |
| 423 | return 1; |
| 424 | } |
| 425 | |
| 426 | return 0; |
| 427 | } |
| 428 | #else |
| 429 | #define sx_paranoia_check(a,b,c) 0 |
| 430 | #endif |
| 431 | |
| 432 | /* The timeouts. First try 30 times as fast as possible. Then give |
| 433 | the card some time to breathe between accesses. (Otherwise the |
| 434 | processor on the card might not be able to access its OWN bus... */ |
| 435 | |
| 436 | #define TIMEOUT_1 30 |
| 437 | #define TIMEOUT_2 1000000 |
| 438 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | #ifdef DEBUG |
| 440 | static void my_hd_io(void __iomem *p, int len) |
| 441 | { |
| 442 | int i, j, ch; |
| 443 | unsigned char __iomem *addr = p; |
| 444 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 445 | for (i = 0; i < len; i += 16) { |
| 446 | printk("%p ", addr + i); |
| 447 | for (j = 0; j < 16; j++) { |
| 448 | printk("%02x %s", readb(addr + j + i), |
| 449 | (j == 7) ? " " : ""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | } |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 451 | for (j = 0; j < 16; j++) { |
| 452 | ch = readb(addr + j + i); |
| 453 | printk("%c", (ch < 0x20) ? '.' : |
| 454 | ((ch > 0x7f) ? '.' : ch)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | } |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 456 | printk("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | } |
| 458 | } |
| 459 | static void my_hd(void *p, int len) |
| 460 | { |
| 461 | int i, j, ch; |
| 462 | unsigned char *addr = p; |
| 463 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 464 | for (i = 0; i < len; i += 16) { |
| 465 | printk("%p ", addr + i); |
| 466 | for (j = 0; j < 16; j++) { |
| 467 | printk("%02x %s", addr[j + i], (j == 7) ? " " : ""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | } |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 469 | for (j = 0; j < 16; j++) { |
| 470 | ch = addr[j + i]; |
| 471 | printk("%c", (ch < 0x20) ? '.' : |
| 472 | ((ch > 0x7f) ? '.' : ch)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | } |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 474 | printk("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | } |
| 476 | } |
| 477 | #endif |
| 478 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | /* This needs redoing for Alpha -- REW -- Done. */ |
| 480 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 481 | static inline void write_sx_byte(struct sx_board *board, int offset, u8 byte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 483 | writeb(byte, board->base + offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | } |
| 485 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 486 | static inline u8 read_sx_byte(struct sx_board *board, int offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 488 | return readb(board->base + offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | } |
| 490 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 491 | static inline void write_sx_word(struct sx_board *board, int offset, u16 word) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 493 | writew(word, board->base + offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | } |
| 495 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 496 | static inline u16 read_sx_word(struct sx_board *board, int offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 498 | return readw(board->base + offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | } |
| 500 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 501 | static int sx_busy_wait_eq(struct sx_board *board, |
| 502 | int offset, int mask, int correctval) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | { |
| 504 | int i; |
| 505 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 506 | func_enter(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 508 | for (i = 0; i < TIMEOUT_1; i++) |
| 509 | if ((read_sx_byte(board, offset) & mask) == correctval) { |
| 510 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | return 1; |
| 512 | } |
| 513 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 514 | for (i = 0; i < TIMEOUT_2; i++) { |
| 515 | if ((read_sx_byte(board, offset) & mask) == correctval) { |
| 516 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | return 1; |
| 518 | } |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 519 | udelay(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | } |
| 521 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 522 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | return 0; |
| 524 | } |
| 525 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 526 | static int sx_busy_wait_neq(struct sx_board *board, |
| 527 | int offset, int mask, int badval) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | { |
| 529 | int i; |
| 530 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 531 | func_enter(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 533 | for (i = 0; i < TIMEOUT_1; i++) |
| 534 | if ((read_sx_byte(board, offset) & mask) != badval) { |
| 535 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | return 1; |
| 537 | } |
| 538 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 539 | for (i = 0; i < TIMEOUT_2; i++) { |
| 540 | if ((read_sx_byte(board, offset) & mask) != badval) { |
| 541 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | return 1; |
| 543 | } |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 544 | udelay(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | } |
| 546 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 547 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | return 0; |
| 549 | } |
| 550 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | /* 5.6.4 of 6210028 r2.3 */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 552 | static int sx_reset(struct sx_board *board) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 554 | func_enter(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 556 | if (IS_SX_BOARD(board)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 558 | write_sx_byte(board, SX_CONFIG, 0); |
| 559 | write_sx_byte(board, SX_RESET, 1); /* Value doesn't matter */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 561 | if (!sx_busy_wait_eq(board, SX_RESET_STATUS, 1, 0)) { |
| 562 | printk(KERN_INFO "sx: Card doesn't respond to " |
| 563 | "reset...\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | return 0; |
| 565 | } |
| 566 | } else if (IS_EISA_BOARD(board)) { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 567 | outb(board->irq << 4, board->eisa_base + 0xc02); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | } else if (IS_SI1_BOARD(board)) { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 569 | write_sx_byte(board, SI1_ISA_RESET, 0); /*value doesn't matter*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | } else { |
| 571 | /* Gory details of the SI/ISA board */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 572 | write_sx_byte(board, SI2_ISA_RESET, SI2_ISA_RESET_SET); |
| 573 | write_sx_byte(board, SI2_ISA_IRQ11, SI2_ISA_IRQ11_CLEAR); |
| 574 | write_sx_byte(board, SI2_ISA_IRQ12, SI2_ISA_IRQ12_CLEAR); |
| 575 | write_sx_byte(board, SI2_ISA_IRQ15, SI2_ISA_IRQ15_CLEAR); |
| 576 | write_sx_byte(board, SI2_ISA_INTCLEAR, SI2_ISA_INTCLEAR_CLEAR); |
| 577 | write_sx_byte(board, SI2_ISA_IRQSET, SI2_ISA_IRQSET_CLEAR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | } |
| 579 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 580 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | return 1; |
| 582 | } |
| 583 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | /* This doesn't work on machines where "NULL" isn't 0 */ |
| 585 | /* If you have one of those, someone will need to write |
| 586 | the equivalent of this, which will amount to about 3 lines. I don't |
| 587 | want to complicate this right now. -- REW |
| 588 | (See, I do write comments every now and then :-) */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 589 | #define OFFSETOF(strct, elem) ((long)&(((struct strct *)NULL)->elem)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 591 | #define CHAN_OFFSET(port,elem) (port->ch_base + OFFSETOF (_SXCHANNEL, elem)) |
| 592 | #define MODU_OFFSET(board,addr,elem) (addr + OFFSETOF (_SXMODULE, elem)) |
| 593 | #define BRD_OFFSET(board,elem) (OFFSETOF (_SXCARD, elem)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | |
| 595 | #define sx_write_channel_byte(port, elem, val) \ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 596 | write_sx_byte (port->board, CHAN_OFFSET (port, elem), val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | |
| 598 | #define sx_read_channel_byte(port, elem) \ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 599 | read_sx_byte (port->board, CHAN_OFFSET (port, elem)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | |
| 601 | #define sx_write_channel_word(port, elem, val) \ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 602 | write_sx_word (port->board, CHAN_OFFSET (port, elem), val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | |
| 604 | #define sx_read_channel_word(port, elem) \ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 605 | read_sx_word (port->board, CHAN_OFFSET (port, elem)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | |
| 607 | #define sx_write_module_byte(board, addr, elem, val) \ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 608 | write_sx_byte (board, MODU_OFFSET (board, addr, elem), val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | |
| 610 | #define sx_read_module_byte(board, addr, elem) \ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 611 | read_sx_byte (board, MODU_OFFSET (board, addr, elem)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | |
| 613 | #define sx_write_module_word(board, addr, elem, val) \ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 614 | write_sx_word (board, MODU_OFFSET (board, addr, elem), val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | |
| 616 | #define sx_read_module_word(board, addr, elem) \ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 617 | read_sx_word (board, MODU_OFFSET (board, addr, elem)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | |
| 619 | #define sx_write_board_byte(board, elem, val) \ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 620 | write_sx_byte (board, BRD_OFFSET (board, elem), val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | |
| 622 | #define sx_read_board_byte(board, elem) \ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 623 | read_sx_byte (board, BRD_OFFSET (board, elem)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | |
| 625 | #define sx_write_board_word(board, elem, val) \ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 626 | write_sx_word (board, BRD_OFFSET (board, elem), val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | |
| 628 | #define sx_read_board_word(board, elem) \ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 629 | read_sx_word (board, BRD_OFFSET (board, elem)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 631 | static int sx_start_board(struct sx_board *board) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 633 | if (IS_SX_BOARD(board)) { |
| 634 | write_sx_byte(board, SX_CONFIG, SX_CONF_BUSEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | } else if (IS_EISA_BOARD(board)) { |
| 636 | write_sx_byte(board, SI2_EISA_OFF, SI2_EISA_VAL); |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 637 | outb((board->irq << 4) | 4, board->eisa_base + 0xc02); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | } else if (IS_SI1_BOARD(board)) { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 639 | write_sx_byte(board, SI1_ISA_RESET_CLEAR, 0); |
| 640 | write_sx_byte(board, SI1_ISA_INTCL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | } else { |
| 642 | /* Don't bug me about the clear_set. |
| 643 | I haven't the foggiest idea what it's about -- REW */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 644 | write_sx_byte(board, SI2_ISA_RESET, SI2_ISA_RESET_CLEAR); |
| 645 | write_sx_byte(board, SI2_ISA_INTCLEAR, SI2_ISA_INTCLEAR_SET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | } |
| 647 | return 1; |
| 648 | } |
| 649 | |
| 650 | #define SX_IRQ_REG_VAL(board) \ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 651 | ((board->flags & SX_ISA_BOARD) ? (board->irq << 4) : 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | |
| 653 | /* Note. The SX register is write-only. Therefore, we have to enable the |
| 654 | bus too. This is a no-op, if you don't mess with this driver... */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 655 | static int sx_start_interrupts(struct sx_board *board) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | { |
| 657 | |
| 658 | /* Don't call this with board->irq == 0 */ |
| 659 | |
| 660 | if (IS_SX_BOARD(board)) { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 661 | write_sx_byte(board, SX_CONFIG, SX_IRQ_REG_VAL(board) | |
| 662 | SX_CONF_BUSEN | SX_CONF_HOSTIRQ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | } else if (IS_EISA_BOARD(board)) { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 664 | inb(board->eisa_base + 0xc03); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | } else if (IS_SI1_BOARD(board)) { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 666 | write_sx_byte(board, SI1_ISA_INTCL, 0); |
| 667 | write_sx_byte(board, SI1_ISA_INTCL_CLEAR, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | } else { |
| 669 | switch (board->irq) { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 670 | case 11: |
| 671 | write_sx_byte(board, SI2_ISA_IRQ11, SI2_ISA_IRQ11_SET); |
| 672 | break; |
| 673 | case 12: |
| 674 | write_sx_byte(board, SI2_ISA_IRQ12, SI2_ISA_IRQ12_SET); |
| 675 | break; |
| 676 | case 15: |
| 677 | write_sx_byte(board, SI2_ISA_IRQ15, SI2_ISA_IRQ15_SET); |
| 678 | break; |
| 679 | default: |
| 680 | printk(KERN_INFO "sx: SI/XIO card doesn't support " |
| 681 | "interrupt %d.\n", board->irq); |
| 682 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | } |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 684 | write_sx_byte(board, SI2_ISA_INTCLEAR, SI2_ISA_INTCLEAR_SET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | return 1; |
| 688 | } |
| 689 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 690 | static int sx_send_command(struct sx_port *port, |
| 691 | int command, int mask, int newstat) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 693 | func_enter2(); |
| 694 | write_sx_byte(port->board, CHAN_OFFSET(port, hi_hstat), command); |
| 695 | func_exit(); |
| 696 | return sx_busy_wait_eq(port->board, CHAN_OFFSET(port, hi_hstat), mask, |
| 697 | newstat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | } |
| 699 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 700 | static char *mod_type_s(int module_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | { |
| 702 | switch (module_type) { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 703 | case TA4: |
| 704 | return "TA4"; |
| 705 | case TA8: |
| 706 | return "TA8"; |
| 707 | case TA4_ASIC: |
| 708 | return "TA4_ASIC"; |
| 709 | case TA8_ASIC: |
| 710 | return "TA8_ASIC"; |
| 711 | case MTA_CD1400: |
| 712 | return "MTA_CD1400"; |
| 713 | case SXDC: |
| 714 | return "SXDC"; |
| 715 | default: |
| 716 | return "Unknown/invalid"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | } |
| 718 | } |
| 719 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 720 | static char *pan_type_s(int pan_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | { |
| 722 | switch (pan_type) { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 723 | case MOD_RS232DB25: |
| 724 | return "MOD_RS232DB25"; |
| 725 | case MOD_RS232RJ45: |
| 726 | return "MOD_RS232RJ45"; |
| 727 | case MOD_RS422DB25: |
| 728 | return "MOD_RS422DB25"; |
| 729 | case MOD_PARALLEL: |
| 730 | return "MOD_PARALLEL"; |
| 731 | case MOD_2_RS232DB25: |
| 732 | return "MOD_2_RS232DB25"; |
| 733 | case MOD_2_RS232RJ45: |
| 734 | return "MOD_2_RS232RJ45"; |
| 735 | case MOD_2_RS422DB25: |
| 736 | return "MOD_2_RS422DB25"; |
| 737 | case MOD_RS232DB25MALE: |
| 738 | return "MOD_RS232DB25MALE"; |
| 739 | case MOD_2_PARALLEL: |
| 740 | return "MOD_2_PARALLEL"; |
| 741 | case MOD_BLANK: |
| 742 | return "empty"; |
| 743 | default: |
| 744 | return "invalid"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | } |
| 746 | } |
| 747 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 748 | static int mod_compat_type(int module_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | { |
| 750 | return module_type >> 4; |
| 751 | } |
| 752 | |
| 753 | static void sx_reconfigure_port(struct sx_port *port) |
| 754 | { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 755 | if (sx_read_channel_byte(port, hi_hstat) == HS_IDLE_OPEN) { |
| 756 | if (sx_send_command(port, HS_CONFIG, -1, HS_IDLE_OPEN) != 1) { |
| 757 | printk(KERN_WARNING "sx: Sent reconfigure command, but " |
| 758 | "card didn't react.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | } |
| 760 | } else { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 761 | sx_dprintk(SX_DEBUG_TERMIOS, "sx: Not sending reconfigure: " |
| 762 | "port isn't open (%02x).\n", |
| 763 | sx_read_channel_byte(port, hi_hstat)); |
| 764 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | } |
| 766 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 767 | static void sx_setsignals(struct sx_port *port, int dtr, int rts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | { |
| 769 | int t; |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 770 | func_enter2(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 772 | t = sx_read_channel_byte(port, hi_op); |
| 773 | if (dtr >= 0) |
| 774 | t = dtr ? (t | OP_DTR) : (t & ~OP_DTR); |
| 775 | if (rts >= 0) |
| 776 | t = rts ? (t | OP_RTS) : (t & ~OP_RTS); |
| 777 | sx_write_channel_byte(port, hi_op, t); |
| 778 | sx_dprintk(SX_DEBUG_MODEMSIGNALS, "setsignals: %d/%d\n", dtr, rts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 780 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | } |
| 782 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 783 | static int sx_getsignals(struct sx_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 785 | int i_stat, o_stat; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 787 | o_stat = sx_read_channel_byte(port, hi_op); |
| 788 | i_stat = sx_read_channel_byte(port, hi_ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 790 | sx_dprintk(SX_DEBUG_MODEMSIGNALS, "getsignals: %d/%d (%d/%d) " |
| 791 | "%02x/%02x\n", |
| 792 | (o_stat & OP_DTR) != 0, (o_stat & OP_RTS) != 0, |
Alan Cox | 31f3593 | 2009-01-02 13:45:05 +0000 | [diff] [blame] | 793 | port->c_dcd, tty_port_carrier_raised(&port->gs.port), |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 794 | sx_read_channel_byte(port, hi_ip), |
| 795 | sx_read_channel_byte(port, hi_state)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 797 | return (((o_stat & OP_DTR) ? TIOCM_DTR : 0) | |
| 798 | ((o_stat & OP_RTS) ? TIOCM_RTS : 0) | |
| 799 | ((i_stat & IP_CTS) ? TIOCM_CTS : 0) | |
| 800 | ((i_stat & IP_DCD) ? TIOCM_CAR : 0) | |
| 801 | ((i_stat & IP_DSR) ? TIOCM_DSR : 0) | |
| 802 | ((i_stat & IP_RI) ? TIOCM_RNG : 0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | } |
| 804 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 805 | static void sx_set_baud(struct sx_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | { |
| 807 | int t; |
| 808 | |
| 809 | if (port->board->ta_type == MOD_SXDC) { |
| 810 | switch (port->gs.baud) { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 811 | /* Save some typing work... */ |
| 812 | #define e(x) case x: t = BAUD_ ## x; break |
| 813 | e(50); |
| 814 | e(75); |
| 815 | e(110); |
| 816 | e(150); |
| 817 | e(200); |
| 818 | e(300); |
| 819 | e(600); |
| 820 | e(1200); |
| 821 | e(1800); |
| 822 | e(2000); |
| 823 | e(2400); |
| 824 | e(4800); |
| 825 | e(7200); |
| 826 | e(9600); |
| 827 | e(14400); |
| 828 | e(19200); |
| 829 | e(28800); |
| 830 | e(38400); |
| 831 | e(56000); |
| 832 | e(57600); |
| 833 | e(64000); |
| 834 | e(76800); |
| 835 | e(115200); |
| 836 | e(128000); |
| 837 | e(150000); |
| 838 | e(230400); |
| 839 | e(256000); |
| 840 | e(460800); |
| 841 | e(921600); |
| 842 | case 134: |
| 843 | t = BAUD_134_5; |
| 844 | break; |
| 845 | case 0: |
| 846 | t = -1; |
| 847 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | default: |
| 849 | /* Can I return "invalid"? */ |
| 850 | t = BAUD_9600; |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 851 | printk(KERN_INFO "sx: unsupported baud rate: %d.\n", |
| 852 | port->gs.baud); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | break; |
| 854 | } |
| 855 | #undef e |
| 856 | if (t > 0) { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 857 | /* The baud rate is not set to 0, so we're enabeling DTR... -- REW */ |
| 858 | sx_setsignals(port, 1, -1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | /* XXX This is not TA & MTA compatible */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 860 | sx_write_channel_byte(port, hi_csr, 0xff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 862 | sx_write_channel_byte(port, hi_txbaud, t); |
| 863 | sx_write_channel_byte(port, hi_rxbaud, t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | } else { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 865 | sx_setsignals(port, 0, -1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | } |
| 867 | } else { |
| 868 | switch (port->gs.baud) { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 869 | #define e(x) case x: t = CSR_ ## x; break |
| 870 | e(75); |
| 871 | e(150); |
| 872 | e(300); |
| 873 | e(600); |
| 874 | e(1200); |
| 875 | e(2400); |
| 876 | e(4800); |
| 877 | e(1800); |
| 878 | e(9600); |
| 879 | e(19200); |
| 880 | e(57600); |
| 881 | e(38400); |
| 882 | /* TA supports 110, but not 115200, MTA supports 115200, but not 110 */ |
| 883 | case 110: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | if (port->board->ta_type == MOD_TA) { |
| 885 | t = CSR_110; |
| 886 | break; |
| 887 | } else { |
| 888 | t = CSR_9600; |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 889 | printk(KERN_INFO "sx: Unsupported baud rate: " |
| 890 | "%d.\n", port->gs.baud); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | break; |
| 892 | } |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 893 | case 115200: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | if (port->board->ta_type == MOD_TA) { |
| 895 | t = CSR_9600; |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 896 | printk(KERN_INFO "sx: Unsupported baud rate: " |
| 897 | "%d.\n", port->gs.baud); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | break; |
| 899 | } else { |
| 900 | t = CSR_110; |
| 901 | break; |
| 902 | } |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 903 | case 0: |
| 904 | t = -1; |
| 905 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | default: |
| 907 | t = CSR_9600; |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 908 | printk(KERN_INFO "sx: Unsupported baud rate: %d.\n", |
| 909 | port->gs.baud); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | break; |
| 911 | } |
| 912 | #undef e |
| 913 | if (t >= 0) { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 914 | sx_setsignals(port, 1, -1); |
| 915 | sx_write_channel_byte(port, hi_csr, t * 0x11); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | } else { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 917 | sx_setsignals(port, 0, -1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | } |
| 919 | } |
| 920 | } |
| 921 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | /* Simon Allen's version of this routine was 225 lines long. 85 is a lot |
| 923 | better. -- REW */ |
| 924 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 925 | static int sx_set_real_termios(void *ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | { |
| 927 | struct sx_port *port = ptr; |
| 928 | |
| 929 | func_enter2(); |
| 930 | |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 931 | if (!port->gs.port.tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | return 0; |
| 933 | |
| 934 | /* What is this doing here? -- REW |
| 935 | Ha! figured it out. It is to allow you to get DTR active again |
| 936 | if you've dropped it with stty 0. Moved to set_baud, where it |
| 937 | belongs (next to the drop dtr if baud == 0) -- REW */ |
| 938 | /* sx_setsignals (port, 1, -1); */ |
| 939 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 940 | sx_set_baud(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 942 | #define CFLAG port->gs.port.tty->termios->c_cflag |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 943 | sx_write_channel_byte(port, hi_mr1, |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 944 | (C_PARENB(port->gs.port.tty) ? MR1_WITH : MR1_NONE) | |
| 945 | (C_PARODD(port->gs.port.tty) ? MR1_ODD : MR1_EVEN) | |
| 946 | (C_CRTSCTS(port->gs.port.tty) ? MR1_RTS_RXFLOW : 0) | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 947 | (((CFLAG & CSIZE) == CS8) ? MR1_8_BITS : 0) | |
| 948 | (((CFLAG & CSIZE) == CS7) ? MR1_7_BITS : 0) | |
| 949 | (((CFLAG & CSIZE) == CS6) ? MR1_6_BITS : 0) | |
| 950 | (((CFLAG & CSIZE) == CS5) ? MR1_5_BITS : 0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 952 | sx_write_channel_byte(port, hi_mr2, |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 953 | (C_CRTSCTS(port->gs.port.tty) ? MR2_CTS_TXFLOW : 0) | |
| 954 | (C_CSTOPB(port->gs.port.tty) ? MR2_2_STOP : |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 955 | MR2_1_STOP)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | |
| 957 | switch (CFLAG & CSIZE) { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 958 | case CS8: |
| 959 | sx_write_channel_byte(port, hi_mask, 0xff); |
| 960 | break; |
| 961 | case CS7: |
| 962 | sx_write_channel_byte(port, hi_mask, 0x7f); |
| 963 | break; |
| 964 | case CS6: |
| 965 | sx_write_channel_byte(port, hi_mask, 0x3f); |
| 966 | break; |
| 967 | case CS5: |
| 968 | sx_write_channel_byte(port, hi_mask, 0x1f); |
| 969 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | default: |
Andrew Morton | 32fb3ca | 2008-05-06 20:42:35 -0700 | [diff] [blame] | 971 | printk(KERN_INFO "sx: Invalid wordsize: %u\n", |
| 972 | (unsigned int)CFLAG & CSIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | break; |
| 974 | } |
| 975 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 976 | sx_write_channel_byte(port, hi_prtcl, |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 977 | (I_IXON(port->gs.port.tty) ? SP_TXEN : 0) | |
| 978 | (I_IXOFF(port->gs.port.tty) ? SP_RXEN : 0) | |
| 979 | (I_IXANY(port->gs.port.tty) ? SP_TANY : 0) | SP_DCEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 981 | sx_write_channel_byte(port, hi_break, |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 982 | (I_IGNBRK(port->gs.port.tty) ? BR_IGN : 0 | |
| 983 | I_BRKINT(port->gs.port.tty) ? BR_INT : 0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 985 | sx_write_channel_byte(port, hi_txon, START_CHAR(port->gs.port.tty)); |
| 986 | sx_write_channel_byte(port, hi_rxon, START_CHAR(port->gs.port.tty)); |
| 987 | sx_write_channel_byte(port, hi_txoff, STOP_CHAR(port->gs.port.tty)); |
| 988 | sx_write_channel_byte(port, hi_rxoff, STOP_CHAR(port->gs.port.tty)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | |
| 990 | sx_reconfigure_port(port); |
| 991 | |
| 992 | /* Tell line discipline whether we will do input cooking */ |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 993 | if (I_OTHER(port->gs.port.tty)) { |
| 994 | clear_bit(TTY_HW_COOK_IN, &port->gs.port.tty->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | } else { |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 996 | set_bit(TTY_HW_COOK_IN, &port->gs.port.tty->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | } |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 998 | sx_dprintk(SX_DEBUG_TERMIOS, "iflags: %x(%d) ", |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 999 | (unsigned int)port->gs.port.tty->termios->c_iflag, |
| 1000 | I_OTHER(port->gs.port.tty)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | |
| 1002 | /* Tell line discipline whether we will do output cooking. |
| 1003 | * If OPOST is set and no other output flags are set then we can do output |
| 1004 | * processing. Even if only *one* other flag in the O_OTHER group is set |
| 1005 | * we do cooking in software. |
| 1006 | */ |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 1007 | if (O_OPOST(port->gs.port.tty) && !O_OTHER(port->gs.port.tty)) { |
| 1008 | set_bit(TTY_HW_COOK_OUT, &port->gs.port.tty->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | } else { |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 1010 | clear_bit(TTY_HW_COOK_OUT, &port->gs.port.tty->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | } |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1012 | sx_dprintk(SX_DEBUG_TERMIOS, "oflags: %x(%d)\n", |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 1013 | (unsigned int)port->gs.port.tty->termios->c_oflag, |
| 1014 | O_OTHER(port->gs.port.tty)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | /* port->c_dcd = sx_get_CD (port); */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1016 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | return 0; |
| 1018 | } |
| 1019 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 | /* ********************************************************************** * |
| 1021 | * the interrupt related routines * |
| 1022 | * ********************************************************************** */ |
| 1023 | |
| 1024 | /* Note: |
| 1025 | Other drivers use the macro "MIN" to calculate how much to copy. |
| 1026 | This has the disadvantage that it will evaluate parts twice. That's |
| 1027 | expensive when it's IO (and the compiler cannot optimize those away!). |
| 1028 | Moreover, I'm not sure that you're race-free. |
| 1029 | |
| 1030 | I assign a value, and then only allow the value to decrease. This |
| 1031 | is always safe. This makes the code a few lines longer, and you |
| 1032 | know I'm dead against that, but I think it is required in this |
| 1033 | case. */ |
| 1034 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1035 | static void sx_transmit_chars(struct sx_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1036 | { |
| 1037 | int c; |
| 1038 | int tx_ip; |
| 1039 | int txroom; |
| 1040 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1041 | func_enter2(); |
| 1042 | sx_dprintk(SX_DEBUG_TRANSMIT, "Port %p: transmit %d chars\n", |
| 1043 | port, port->gs.xmit_cnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1045 | if (test_and_set_bit(SX_PORT_TRANSMIT_LOCK, &port->locks)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | return; |
| 1047 | } |
| 1048 | |
| 1049 | while (1) { |
| 1050 | c = port->gs.xmit_cnt; |
| 1051 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1052 | sx_dprintk(SX_DEBUG_TRANSMIT, "Copying %d ", c); |
| 1053 | tx_ip = sx_read_channel_byte(port, hi_txipos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | |
| 1055 | /* Took me 5 minutes to deduce this formula. |
| 1056 | Luckily it is literally in the manual in section 6.5.4.3.5 */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1057 | txroom = (sx_read_channel_byte(port, hi_txopos) - tx_ip - 1) & |
| 1058 | 0xff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | |
| 1060 | /* Don't copy more bytes than there is room for in the buffer */ |
| 1061 | if (c > txroom) |
| 1062 | c = txroom; |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1063 | sx_dprintk(SX_DEBUG_TRANSMIT, " %d(%d) ", c, txroom); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1064 | |
| 1065 | /* Don't copy past the end of the hardware transmit buffer */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1066 | if (c > 0x100 - tx_ip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | c = 0x100 - tx_ip; |
| 1068 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1069 | sx_dprintk(SX_DEBUG_TRANSMIT, " %d(%d) ", c, 0x100 - tx_ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | |
| 1071 | /* Don't copy pas the end of the source buffer */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1072 | if (c > SERIAL_XMIT_SIZE - port->gs.xmit_tail) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | c = SERIAL_XMIT_SIZE - port->gs.xmit_tail; |
| 1074 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1075 | sx_dprintk(SX_DEBUG_TRANSMIT, " %d(%ld) \n", |
| 1076 | c, SERIAL_XMIT_SIZE - port->gs.xmit_tail); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1078 | /* If for one reason or another, we can't copy more data, we're |
| 1079 | done! */ |
| 1080 | if (c == 0) |
| 1081 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1083 | memcpy_toio(port->board->base + CHAN_OFFSET(port, hi_txbuf) + |
| 1084 | tx_ip, port->gs.xmit_buf + port->gs.xmit_tail, c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | |
| 1086 | /* Update the pointer in the card */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1087 | sx_write_channel_byte(port, hi_txipos, (tx_ip + c) & 0xff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | |
| 1089 | /* Update the kernel buffer end */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1090 | port->gs.xmit_tail = (port->gs.xmit_tail + c) & |
| 1091 | (SERIAL_XMIT_SIZE - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | |
| 1093 | /* This one last. (this is essential) |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1094 | It would allow others to start putting more data into the |
| 1095 | buffer! */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | port->gs.xmit_cnt -= c; |
| 1097 | } |
| 1098 | |
| 1099 | if (port->gs.xmit_cnt == 0) { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1100 | sx_disable_tx_interrupts(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | } |
| 1102 | |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 1103 | if ((port->gs.xmit_cnt <= port->gs.wakeup_chars) && port->gs.port.tty) { |
| 1104 | tty_wakeup(port->gs.port.tty); |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1105 | sx_dprintk(SX_DEBUG_TRANSMIT, "Waking up.... ldisc (%d)....\n", |
| 1106 | port->gs.wakeup_chars); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1107 | } |
| 1108 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1109 | clear_bit(SX_PORT_TRANSMIT_LOCK, &port->locks); |
| 1110 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | } |
| 1112 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1113 | /* Note the symmetry between receiving chars and transmitting them! |
| 1114 | Note: The kernel should have implemented both a receive buffer and |
| 1115 | a transmit buffer. */ |
| 1116 | |
| 1117 | /* Inlined: Called only once. Remove the inline when you add another call */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1118 | static inline void sx_receive_chars(struct sx_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | { |
| 1120 | int c; |
| 1121 | int rx_op; |
| 1122 | struct tty_struct *tty; |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1123 | int copied = 0; |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 1124 | unsigned char *rp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1126 | func_enter2(); |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 1127 | tty = port->gs.port.tty; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | while (1) { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1129 | rx_op = sx_read_channel_byte(port, hi_rxopos); |
| 1130 | c = (sx_read_channel_byte(port, hi_rxipos) - rx_op) & 0xff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1132 | sx_dprintk(SX_DEBUG_RECEIVE, "rxop=%d, c = %d.\n", rx_op, c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | |
Marc Zyngier | d904ffd | 2006-02-27 12:08:00 +0100 | [diff] [blame] | 1134 | /* Don't copy past the end of the hardware receive buffer */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1135 | if (rx_op + c > 0x100) |
| 1136 | c = 0x100 - rx_op; |
Marc Zyngier | d904ffd | 2006-02-27 12:08:00 +0100 | [diff] [blame] | 1137 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1138 | sx_dprintk(SX_DEBUG_RECEIVE, "c = %d.\n", c); |
Marc Zyngier | d904ffd | 2006-02-27 12:08:00 +0100 | [diff] [blame] | 1139 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | /* Don't copy more bytes than there is room for in the buffer */ |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 1141 | |
| 1142 | c = tty_prepare_flip_string(tty, &rp, c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1144 | sx_dprintk(SX_DEBUG_RECEIVE, "c = %d.\n", c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1145 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1146 | /* If for one reason or another, we can't copy more data, we're done! */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1147 | if (c == 0) |
| 1148 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1149 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1150 | sx_dprintk(SX_DEBUG_RECEIVE, "Copying over %d chars. First is " |
| 1151 | "%d at %lx\n", c, read_sx_byte(port->board, |
| 1152 | CHAN_OFFSET(port, hi_rxbuf) + rx_op), |
| 1153 | CHAN_OFFSET(port, hi_rxbuf)); |
| 1154 | memcpy_fromio(rp, port->board->base + |
| 1155 | CHAN_OFFSET(port, hi_rxbuf) + rx_op, c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 | |
| 1157 | /* This one last. ( Not essential.) |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1158 | It allows the card to start putting more data into the |
| 1159 | buffer! |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1160 | Update the pointer in the card */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1161 | sx_write_channel_byte(port, hi_rxopos, (rx_op + c) & 0xff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | |
| 1163 | copied += c; |
| 1164 | } |
| 1165 | if (copied) { |
| 1166 | struct timeval tv; |
| 1167 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1168 | do_gettimeofday(&tv); |
| 1169 | sx_dprintk(SX_DEBUG_RECEIVE, "pushing flipq port %d (%3d " |
| 1170 | "chars): %d.%06d (%d/%d)\n", port->line, |
| 1171 | copied, (int)(tv.tv_sec % 60), (int)tv.tv_usec, |
| 1172 | tty->raw, tty->real_raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1173 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1174 | /* Tell the rest of the system the news. Great news. New |
| 1175 | characters! */ |
| 1176 | tty_flip_buffer_push(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | /* tty_schedule_flip (tty); */ |
| 1178 | } |
| 1179 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1180 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | } |
| 1182 | |
| 1183 | /* Inlined: it is called only once. Remove the inline if you add another |
| 1184 | call */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1185 | static inline void sx_check_modem_signals(struct sx_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | { |
| 1187 | int hi_state; |
| 1188 | int c_dcd; |
| 1189 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1190 | hi_state = sx_read_channel_byte(port, hi_state); |
| 1191 | sx_dprintk(SX_DEBUG_MODEMSIGNALS, "Checking modem signals (%d/%d)\n", |
Alan Cox | 31f3593 | 2009-01-02 13:45:05 +0000 | [diff] [blame] | 1192 | port->c_dcd, tty_port_carrier_raised(&port->gs.port)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | |
| 1194 | if (hi_state & ST_BREAK) { |
| 1195 | hi_state &= ~ST_BREAK; |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1196 | sx_dprintk(SX_DEBUG_MODEMSIGNALS, "got a break.\n"); |
| 1197 | sx_write_channel_byte(port, hi_state, hi_state); |
| 1198 | gs_got_break(&port->gs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1199 | } |
| 1200 | if (hi_state & ST_DCD) { |
| 1201 | hi_state &= ~ST_DCD; |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1202 | sx_dprintk(SX_DEBUG_MODEMSIGNALS, "got a DCD change.\n"); |
| 1203 | sx_write_channel_byte(port, hi_state, hi_state); |
Alan Cox | 31f3593 | 2009-01-02 13:45:05 +0000 | [diff] [blame] | 1204 | c_dcd = tty_port_carrier_raised(&port->gs.port); |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1205 | sx_dprintk(SX_DEBUG_MODEMSIGNALS, "DCD is now %d\n", c_dcd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | if (c_dcd != port->c_dcd) { |
| 1207 | port->c_dcd = c_dcd; |
Alan Cox | 31f3593 | 2009-01-02 13:45:05 +0000 | [diff] [blame] | 1208 | if (tty_port_carrier_raised(&port->gs.port)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1209 | /* DCD went UP */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1210 | if ((sx_read_channel_byte(port, hi_hstat) != |
| 1211 | HS_IDLE_CLOSED) && |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 1212 | !(port->gs.port.tty->termios-> |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1213 | c_cflag & CLOCAL)) { |
| 1214 | /* Are we blocking in open? */ |
| 1215 | sx_dprintk(SX_DEBUG_MODEMSIGNALS, "DCD " |
| 1216 | "active, unblocking open\n"); |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 1217 | wake_up_interruptible(&port->gs.port. |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1218 | open_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1219 | } else { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1220 | sx_dprintk(SX_DEBUG_MODEMSIGNALS, "DCD " |
| 1221 | "raised. Ignoring.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1222 | } |
| 1223 | } else { |
| 1224 | /* DCD went down! */ |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 1225 | if (!(port->gs.port.tty->termios->c_cflag & CLOCAL)){ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1226 | sx_dprintk(SX_DEBUG_MODEMSIGNALS, "DCD " |
| 1227 | "dropped. hanging up....\n"); |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 1228 | tty_hangup(port->gs.port.tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1229 | } else { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1230 | sx_dprintk(SX_DEBUG_MODEMSIGNALS, "DCD " |
| 1231 | "dropped. ignoring.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | } |
| 1233 | } |
| 1234 | } else { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1235 | sx_dprintk(SX_DEBUG_MODEMSIGNALS, "Hmmm. card told us " |
| 1236 | "DCD changed, but it didn't.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1237 | } |
| 1238 | } |
| 1239 | } |
| 1240 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1241 | /* This is what an interrupt routine should look like. |
| 1242 | * Small, elegant, clear. |
| 1243 | */ |
| 1244 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1245 | static irqreturn_t sx_interrupt(int irq, void *ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | { |
| 1247 | struct sx_board *board = ptr; |
| 1248 | struct sx_port *port; |
| 1249 | int i; |
| 1250 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1251 | func_enter(); |
| 1252 | sx_dprintk(SX_DEBUG_FLOW, "sx: enter sx_interrupt (%d/%d)\n", irq, |
| 1253 | board->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | |
| 1255 | /* AAargh! The order in which to do these things is essential and |
| 1256 | not trivial. |
| 1257 | |
| 1258 | - Rate limit goes before "recursive". Otherwise a series of |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1259 | recursive calls will hang the machine in the interrupt routine. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1260 | |
| 1261 | - hardware twiddling goes before "recursive". Otherwise when we |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1262 | poll the card, and a recursive interrupt happens, we won't |
| 1263 | ack the card, so it might keep on interrupting us. (especially |
| 1264 | level sensitive interrupt systems like PCI). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | |
| 1266 | - Rate limit goes before hardware twiddling. Otherwise we won't |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1267 | catch a card that has gone bonkers. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | |
| 1269 | - The "initialized" test goes after the hardware twiddling. Otherwise |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1270 | the card will stick us in the interrupt routine again. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1271 | |
| 1272 | - The initialized test goes before recursive. |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1273 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1274 | |
| 1275 | #ifdef IRQ_RATE_LIMIT |
| 1276 | /* Aaargh! I'm ashamed. This costs more lines-of-code than the |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1277 | actual interrupt routine!. (Well, used to when I wrote that |
| 1278 | comment) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | { |
| 1280 | static int lastjif; |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1281 | static int nintr = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1282 | |
| 1283 | if (lastjif == jiffies) { |
| 1284 | if (++nintr > IRQ_RATE_LIMIT) { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1285 | free_irq(board->irq, board); |
| 1286 | printk(KERN_ERR "sx: Too many interrupts. " |
| 1287 | "Turning off interrupt %d.\n", |
| 1288 | board->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1289 | } |
| 1290 | } else { |
| 1291 | lastjif = jiffies; |
| 1292 | nintr = 0; |
| 1293 | } |
| 1294 | } |
| 1295 | #endif |
| 1296 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1297 | if (board->irq == irq) { |
| 1298 | /* Tell the card we've noticed the interrupt. */ |
| 1299 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1300 | sx_write_board_word(board, cc_int_pending, 0); |
| 1301 | if (IS_SX_BOARD(board)) { |
| 1302 | write_sx_byte(board, SX_RESET_IRQ, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1303 | } else if (IS_EISA_BOARD(board)) { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1304 | inb(board->eisa_base + 0xc03); |
| 1305 | write_sx_word(board, 8, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | } else { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1307 | write_sx_byte(board, SI2_ISA_INTCLEAR, |
| 1308 | SI2_ISA_INTCLEAR_CLEAR); |
| 1309 | write_sx_byte(board, SI2_ISA_INTCLEAR, |
| 1310 | SI2_ISA_INTCLEAR_SET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1311 | } |
| 1312 | } |
| 1313 | |
| 1314 | if (!sx_initialized) |
| 1315 | return IRQ_HANDLED; |
| 1316 | if (!(board->flags & SX_BOARD_INITIALIZED)) |
| 1317 | return IRQ_HANDLED; |
| 1318 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1319 | if (test_and_set_bit(SX_BOARD_INTR_LOCK, &board->locks)) { |
| 1320 | printk(KERN_ERR "Recursive interrupt! (%d)\n", board->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | return IRQ_HANDLED; |
| 1322 | } |
| 1323 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1324 | for (i = 0; i < board->nports; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1325 | port = &board->ports[i]; |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 1326 | if (port->gs.port.flags & GS_ACTIVE) { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1327 | if (sx_read_channel_byte(port, hi_state)) { |
| 1328 | sx_dprintk(SX_DEBUG_INTERRUPTS, "Port %d: " |
| 1329 | "modem signal change?... \n",i); |
| 1330 | sx_check_modem_signals(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1331 | } |
| 1332 | if (port->gs.xmit_cnt) { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1333 | sx_transmit_chars(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1334 | } |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 1335 | if (!(port->gs.port.flags & SX_RX_THROTTLE)) { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1336 | sx_receive_chars(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | } |
| 1338 | } |
| 1339 | } |
| 1340 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1341 | clear_bit(SX_BOARD_INTR_LOCK, &board->locks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1343 | sx_dprintk(SX_DEBUG_FLOW, "sx: exit sx_interrupt (%d/%d)\n", irq, |
| 1344 | board->irq); |
| 1345 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1346 | return IRQ_HANDLED; |
| 1347 | } |
| 1348 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1349 | static void sx_pollfunc(unsigned long data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1351 | struct sx_board *board = (struct sx_board *)data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1352 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1353 | func_enter(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1354 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1355 | sx_interrupt(0, board); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1356 | |
Jiri Slaby | c959464 | 2006-12-08 02:39:05 -0800 | [diff] [blame] | 1357 | mod_timer(&board->timer, jiffies + sx_poll); |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1358 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1359 | } |
| 1360 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1361 | /* ********************************************************************** * |
| 1362 | * Here are the routines that actually * |
| 1363 | * interface with the generic_serial driver * |
| 1364 | * ********************************************************************** */ |
| 1365 | |
| 1366 | /* Ehhm. I don't know how to fiddle with interrupts on the SX card. --REW */ |
| 1367 | /* Hmm. Ok I figured it out. You don't. */ |
| 1368 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1369 | static void sx_disable_tx_interrupts(void *ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1370 | { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1371 | struct sx_port *port = ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1372 | func_enter2(); |
| 1373 | |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 1374 | port->gs.port.flags &= ~GS_TX_INTEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1375 | |
| 1376 | func_exit(); |
| 1377 | } |
| 1378 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1379 | static void sx_enable_tx_interrupts(void *ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1380 | { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1381 | struct sx_port *port = ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1382 | int data_in_buffer; |
| 1383 | func_enter2(); |
| 1384 | |
| 1385 | /* First transmit the characters that we're supposed to */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1386 | sx_transmit_chars(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | |
| 1388 | /* The sx card will never interrupt us if we don't fill the buffer |
| 1389 | past 25%. So we keep considering interrupts off if that's the case. */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1390 | data_in_buffer = (sx_read_channel_byte(port, hi_txipos) - |
| 1391 | sx_read_channel_byte(port, hi_txopos)) & 0xff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1392 | |
| 1393 | /* XXX Must be "HIGH_WATER" for SI card according to doc. */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1394 | if (data_in_buffer < LOW_WATER) |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 1395 | port->gs.port.flags &= ~GS_TX_INTEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1396 | |
| 1397 | func_exit(); |
| 1398 | } |
| 1399 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1400 | static void sx_disable_rx_interrupts(void *ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1401 | { |
| 1402 | /* struct sx_port *port = ptr; */ |
| 1403 | func_enter(); |
| 1404 | |
| 1405 | func_exit(); |
| 1406 | } |
| 1407 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1408 | static void sx_enable_rx_interrupts(void *ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1409 | { |
| 1410 | /* struct sx_port *port = ptr; */ |
| 1411 | func_enter(); |
| 1412 | |
| 1413 | func_exit(); |
| 1414 | } |
| 1415 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1416 | /* Jeez. Isn't this simple? */ |
Alan Cox | 31f3593 | 2009-01-02 13:45:05 +0000 | [diff] [blame] | 1417 | static int sx_carrier_raised(struct tty_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1418 | { |
Alan Cox | 31f3593 | 2009-01-02 13:45:05 +0000 | [diff] [blame] | 1419 | struct sx_port *sp = container_of(port, struct sx_port, gs.port); |
| 1420 | return ((sx_read_channel_byte(sp, hi_ip) & IP_DCD) != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1421 | } |
| 1422 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1423 | /* Jeez. Isn't this simple? */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1424 | static int sx_chars_in_buffer(void *ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1425 | { |
| 1426 | struct sx_port *port = ptr; |
| 1427 | func_enter2(); |
| 1428 | |
| 1429 | func_exit(); |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1430 | return ((sx_read_channel_byte(port, hi_txipos) - |
| 1431 | sx_read_channel_byte(port, hi_txopos)) & 0xff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1432 | } |
| 1433 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1434 | static void sx_shutdown_port(void *ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1435 | { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1436 | struct sx_port *port = ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1437 | |
| 1438 | func_enter(); |
| 1439 | |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 1440 | port->gs.port.flags &= ~GS_ACTIVE; |
| 1441 | if (port->gs.port.tty && (port->gs.port.tty->termios->c_cflag & HUPCL)) { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1442 | sx_setsignals(port, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1443 | sx_reconfigure_port(port); |
| 1444 | } |
| 1445 | |
| 1446 | func_exit(); |
| 1447 | } |
| 1448 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1449 | /* ********************************************************************** * |
| 1450 | * Here are the routines that actually * |
| 1451 | * interface with the rest of the system * |
| 1452 | * ********************************************************************** */ |
| 1453 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1454 | static int sx_open(struct tty_struct *tty, struct file *filp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1455 | { |
| 1456 | struct sx_port *port; |
| 1457 | int retval, line; |
| 1458 | unsigned long flags; |
| 1459 | |
| 1460 | func_enter(); |
| 1461 | |
| 1462 | if (!sx_initialized) { |
| 1463 | return -EIO; |
| 1464 | } |
| 1465 | |
| 1466 | line = tty->index; |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1467 | sx_dprintk(SX_DEBUG_OPEN, "%d: opening line %d. tty=%p ctty=%p, " |
Pavel Emelyanov | ba25f9d | 2007-10-18 23:40:40 -0700 | [diff] [blame] | 1468 | "np=%d)\n", task_pid_nr(current), line, tty, |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1469 | current->signal->tty, sx_nports); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1470 | |
| 1471 | if ((line < 0) || (line >= SX_NPORTS) || (line >= sx_nports)) |
| 1472 | return -ENODEV; |
| 1473 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1474 | port = &sx_ports[line]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1475 | port->c_dcd = 0; /* Make sure that the first interrupt doesn't detect a |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1476 | 1 -> 0 transition. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1477 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1478 | sx_dprintk(SX_DEBUG_OPEN, "port = %p c_dcd = %d\n", port, port->c_dcd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1479 | |
| 1480 | spin_lock_irqsave(&port->gs.driver_lock, flags); |
| 1481 | |
| 1482 | tty->driver_data = port; |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 1483 | port->gs.port.tty = tty; |
| 1484 | port->gs.port.count++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1485 | spin_unlock_irqrestore(&port->gs.driver_lock, flags); |
| 1486 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1487 | sx_dprintk(SX_DEBUG_OPEN, "starting port\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | |
| 1489 | /* |
| 1490 | * Start up serial port |
| 1491 | */ |
| 1492 | retval = gs_init_port(&port->gs); |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1493 | sx_dprintk(SX_DEBUG_OPEN, "done gs_init\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1494 | if (retval) { |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 1495 | port->gs.port.count--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1496 | return retval; |
| 1497 | } |
| 1498 | |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 1499 | port->gs.port.flags |= GS_ACTIVE; |
| 1500 | if (port->gs.port.count <= 1) |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1501 | sx_setsignals(port, 1, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1502 | |
| 1503 | #if 0 |
| 1504 | if (sx_debug & SX_DEBUG_OPEN) |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1505 | my_hd(port, sizeof(*port)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1506 | #else |
| 1507 | if (sx_debug & SX_DEBUG_OPEN) |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1508 | my_hd_io(port->board->base + port->ch_base, sizeof(*port)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1509 | #endif |
| 1510 | |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 1511 | if (port->gs.port.count <= 1) { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1512 | if (sx_send_command(port, HS_LOPEN, -1, HS_IDLE_OPEN) != 1) { |
| 1513 | printk(KERN_ERR "sx: Card didn't respond to LOPEN " |
| 1514 | "command.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1515 | spin_lock_irqsave(&port->gs.driver_lock, flags); |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 1516 | port->gs.port.count--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1517 | spin_unlock_irqrestore(&port->gs.driver_lock, flags); |
| 1518 | return -EIO; |
| 1519 | } |
| 1520 | } |
| 1521 | |
| 1522 | retval = gs_block_til_ready(port, filp); |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1523 | sx_dprintk(SX_DEBUG_OPEN, "Block til ready returned %d. Count=%d\n", |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 1524 | retval, port->gs.port.count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1525 | |
| 1526 | if (retval) { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1527 | /* |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 1528 | * Don't lower gs.port.count here because sx_close() will be called later |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1529 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1530 | |
| 1531 | return retval; |
| 1532 | } |
| 1533 | /* tty->low_latency = 1; */ |
| 1534 | |
Alan Cox | 31f3593 | 2009-01-02 13:45:05 +0000 | [diff] [blame] | 1535 | port->c_dcd = sx_carrier_raised(&port->gs.port); |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1536 | sx_dprintk(SX_DEBUG_OPEN, "at open: cd=%d\n", port->c_dcd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1537 | |
| 1538 | func_exit(); |
| 1539 | return 0; |
| 1540 | |
| 1541 | } |
| 1542 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1543 | static void sx_close(void *ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1544 | { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1545 | struct sx_port *port = ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1546 | /* Give the port 5 seconds to close down. */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1547 | int to = 5 * HZ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1548 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1549 | func_enter(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1550 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1551 | sx_setsignals(port, 0, 0); |
| 1552 | sx_reconfigure_port(port); |
| 1553 | sx_send_command(port, HS_CLOSE, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1554 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1555 | while (to-- && (sx_read_channel_byte(port, hi_hstat) != HS_IDLE_CLOSED)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1556 | if (msleep_interruptible(10)) |
| 1557 | break; |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1558 | if (sx_read_channel_byte(port, hi_hstat) != HS_IDLE_CLOSED) { |
| 1559 | if (sx_send_command(port, HS_FORCE_CLOSED, -1, HS_IDLE_CLOSED) |
| 1560 | != 1) { |
| 1561 | printk(KERN_ERR "sx: sent the force_close command, but " |
| 1562 | "card didn't react\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1563 | } else |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1564 | sx_dprintk(SX_DEBUG_CLOSE, "sent the force_close " |
| 1565 | "command.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1566 | } |
| 1567 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1568 | sx_dprintk(SX_DEBUG_CLOSE, "waited %d jiffies for close. count=%d\n", |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 1569 | 5 * HZ - to - 1, port->gs.port.count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1570 | |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 1571 | if (port->gs.port.count) { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1572 | sx_dprintk(SX_DEBUG_CLOSE, "WARNING port count:%d\n", |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 1573 | port->gs.port.count); |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1574 | /*printk("%s SETTING port count to zero: %p count: %d\n", |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 1575 | __func__, port, port->gs.port.count); |
| 1576 | port->gs.port.count = 0;*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1577 | } |
| 1578 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1579 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1580 | } |
| 1581 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1582 | /* This is relatively thorough. But then again it is only 20 lines. */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1583 | #define MARCHUP for (i = min; i < max; i++) |
| 1584 | #define MARCHDOWN for (i = max - 1; i >= min; i--) |
| 1585 | #define W0 write_sx_byte(board, i, 0x55) |
| 1586 | #define W1 write_sx_byte(board, i, 0xaa) |
| 1587 | #define R0 if (read_sx_byte(board, i) != 0x55) return 1 |
| 1588 | #define R1 if (read_sx_byte(board, i) != 0xaa) return 1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1589 | |
| 1590 | /* This memtest takes a human-noticable time. You normally only do it |
| 1591 | once a boot, so I guess that it is worth it. */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1592 | static int do_memtest(struct sx_board *board, int min, int max) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 | { |
| 1594 | int i; |
| 1595 | |
| 1596 | /* This is a marchb. Theoretically, marchb catches much more than |
| 1597 | simpler tests. In practise, the longer test just catches more |
| 1598 | intermittent errors. -- REW |
| 1599 | (For the theory behind memory testing see: |
| 1600 | Testing Semiconductor Memories by A.J. van de Goor.) */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1601 | MARCHUP { |
| 1602 | W0; |
| 1603 | } |
| 1604 | MARCHUP { |
| 1605 | R0; |
| 1606 | W1; |
| 1607 | R1; |
| 1608 | W0; |
| 1609 | R0; |
| 1610 | W1; |
| 1611 | } |
| 1612 | MARCHUP { |
| 1613 | R1; |
| 1614 | W0; |
| 1615 | W1; |
| 1616 | } |
| 1617 | MARCHDOWN { |
| 1618 | R1; |
| 1619 | W0; |
| 1620 | W1; |
| 1621 | W0; |
| 1622 | } |
| 1623 | MARCHDOWN { |
| 1624 | R0; |
| 1625 | W1; |
| 1626 | W0; |
| 1627 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1628 | |
| 1629 | return 0; |
| 1630 | } |
| 1631 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1632 | #undef MARCHUP |
| 1633 | #undef MARCHDOWN |
| 1634 | #undef W0 |
| 1635 | #undef W1 |
| 1636 | #undef R0 |
| 1637 | #undef R1 |
| 1638 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1639 | #define MARCHUP for (i = min; i < max; i += 2) |
| 1640 | #define MARCHDOWN for (i = max - 1; i >= min; i -= 2) |
| 1641 | #define W0 write_sx_word(board, i, 0x55aa) |
| 1642 | #define W1 write_sx_word(board, i, 0xaa55) |
| 1643 | #define R0 if (read_sx_word(board, i) != 0x55aa) return 1 |
| 1644 | #define R1 if (read_sx_word(board, i) != 0xaa55) return 1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1645 | |
| 1646 | #if 0 |
| 1647 | /* This memtest takes a human-noticable time. You normally only do it |
| 1648 | once a boot, so I guess that it is worth it. */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1649 | static int do_memtest_w(struct sx_board *board, int min, int max) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1650 | { |
| 1651 | int i; |
| 1652 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1653 | MARCHUP { |
| 1654 | W0; |
| 1655 | } |
| 1656 | MARCHUP { |
| 1657 | R0; |
| 1658 | W1; |
| 1659 | R1; |
| 1660 | W0; |
| 1661 | R0; |
| 1662 | W1; |
| 1663 | } |
| 1664 | MARCHUP { |
| 1665 | R1; |
| 1666 | W0; |
| 1667 | W1; |
| 1668 | } |
| 1669 | MARCHDOWN { |
| 1670 | R1; |
| 1671 | W0; |
| 1672 | W1; |
| 1673 | W0; |
| 1674 | } |
| 1675 | MARCHDOWN { |
| 1676 | R0; |
| 1677 | W1; |
| 1678 | W0; |
| 1679 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1680 | |
| 1681 | return 0; |
| 1682 | } |
| 1683 | #endif |
| 1684 | |
Alan Cox | 11af747 | 2008-07-25 01:48:15 -0700 | [diff] [blame] | 1685 | static long sx_fw_ioctl(struct file *filp, unsigned int cmd, |
| 1686 | unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1687 | { |
Alan Cox | 11af747 | 2008-07-25 01:48:15 -0700 | [diff] [blame] | 1688 | long rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1689 | int __user *descr = (int __user *)arg; |
| 1690 | int i; |
| 1691 | static struct sx_board *board = NULL; |
| 1692 | int nbytes, offset; |
| 1693 | unsigned long data; |
| 1694 | char *tmp; |
| 1695 | |
| 1696 | func_enter(); |
| 1697 | |
Alan Cox | 11af747 | 2008-07-25 01:48:15 -0700 | [diff] [blame] | 1698 | if (!capable(CAP_SYS_RAWIO)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1699 | return -EPERM; |
Alan Cox | 11af747 | 2008-07-25 01:48:15 -0700 | [diff] [blame] | 1700 | |
| 1701 | lock_kernel(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1702 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1703 | sx_dprintk(SX_DEBUG_FIRMWARE, "IOCTL %x: %lx\n", cmd, arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1704 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1705 | if (!board) |
| 1706 | board = &boards[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1707 | if (board->flags & SX_BOARD_PRESENT) { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1708 | sx_dprintk(SX_DEBUG_FIRMWARE, "Board present! (%x)\n", |
| 1709 | board->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1710 | } else { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1711 | sx_dprintk(SX_DEBUG_FIRMWARE, "Board not present! (%x) all:", |
| 1712 | board->flags); |
| 1713 | for (i = 0; i < SX_NBOARDS; i++) |
| 1714 | sx_dprintk(SX_DEBUG_FIRMWARE, "<%x> ", boards[i].flags); |
| 1715 | sx_dprintk(SX_DEBUG_FIRMWARE, "\n"); |
Dan Carpenter | 736d545 | 2009-02-04 15:12:20 -0800 | [diff] [blame] | 1716 | rc = -EIO; |
| 1717 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1718 | } |
| 1719 | |
| 1720 | switch (cmd) { |
| 1721 | case SXIO_SET_BOARD: |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1722 | sx_dprintk(SX_DEBUG_FIRMWARE, "set board to %ld\n", arg); |
Alan Cox | 11af747 | 2008-07-25 01:48:15 -0700 | [diff] [blame] | 1723 | rc = -EIO; |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1724 | if (arg >= SX_NBOARDS) |
Alan Cox | 11af747 | 2008-07-25 01:48:15 -0700 | [diff] [blame] | 1725 | break; |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1726 | sx_dprintk(SX_DEBUG_FIRMWARE, "not out of range\n"); |
| 1727 | if (!(boards[arg].flags & SX_BOARD_PRESENT)) |
Alan Cox | 11af747 | 2008-07-25 01:48:15 -0700 | [diff] [blame] | 1728 | break; |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1729 | sx_dprintk(SX_DEBUG_FIRMWARE, ".. and present!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1730 | board = &boards[arg]; |
Alan Cox | 11af747 | 2008-07-25 01:48:15 -0700 | [diff] [blame] | 1731 | rc = 0; |
| 1732 | /* FIXME: And this does ... nothing?? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1733 | break; |
| 1734 | case SXIO_GET_TYPE: |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1735 | rc = -ENOENT; /* If we manage to miss one, return error. */ |
| 1736 | if (IS_SX_BOARD(board)) |
| 1737 | rc = SX_TYPE_SX; |
| 1738 | if (IS_CF_BOARD(board)) |
| 1739 | rc = SX_TYPE_CF; |
| 1740 | if (IS_SI_BOARD(board)) |
| 1741 | rc = SX_TYPE_SI; |
| 1742 | if (IS_SI1_BOARD(board)) |
| 1743 | rc = SX_TYPE_SI; |
| 1744 | if (IS_EISA_BOARD(board)) |
| 1745 | rc = SX_TYPE_SI; |
Alan Cox | 11af747 | 2008-07-25 01:48:15 -0700 | [diff] [blame] | 1746 | sx_dprintk(SX_DEBUG_FIRMWARE, "returning type= %ld\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1747 | break; |
| 1748 | case SXIO_DO_RAMTEST: |
Ilpo Järvinen | 9b6d251 | 2009-02-20 15:38:45 -0800 | [diff] [blame^] | 1749 | if (sx_initialized) { /* Already initialized: better not ramtest the board. */ |
Dan Carpenter | 736d545 | 2009-02-04 15:12:20 -0800 | [diff] [blame] | 1750 | rc = -EPERM; |
| 1751 | break; |
Ilpo Järvinen | 9b6d251 | 2009-02-20 15:38:45 -0800 | [diff] [blame^] | 1752 | } |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1753 | if (IS_SX_BOARD(board)) { |
| 1754 | rc = do_memtest(board, 0, 0x7000); |
| 1755 | if (!rc) |
| 1756 | rc = do_memtest(board, 0, 0x7000); |
| 1757 | /*if (!rc) rc = do_memtest_w (board, 0, 0x7000); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1758 | } else { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1759 | rc = do_memtest(board, 0, 0x7ff8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1760 | /* if (!rc) rc = do_memtest_w (board, 0, 0x7ff8); */ |
| 1761 | } |
Alan Cox | 11af747 | 2008-07-25 01:48:15 -0700 | [diff] [blame] | 1762 | sx_dprintk(SX_DEBUG_FIRMWARE, |
| 1763 | "returning memtest result= %ld\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1764 | break; |
| 1765 | case SXIO_DOWNLOAD: |
Alan Cox | 11af747 | 2008-07-25 01:48:15 -0700 | [diff] [blame] | 1766 | if (sx_initialized) {/* Already initialized */ |
| 1767 | rc = -EEXIST; |
| 1768 | break; |
| 1769 | } |
| 1770 | if (!sx_reset(board)) { |
| 1771 | rc = -EIO; |
| 1772 | break; |
| 1773 | } |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1774 | sx_dprintk(SX_DEBUG_INIT, "reset the board...\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1775 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1776 | tmp = kmalloc(SX_CHUNK_SIZE, GFP_USER); |
Alan Cox | 11af747 | 2008-07-25 01:48:15 -0700 | [diff] [blame] | 1777 | if (!tmp) { |
| 1778 | rc = -ENOMEM; |
| 1779 | break; |
| 1780 | } |
| 1781 | /* FIXME: check returns */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1782 | get_user(nbytes, descr++); |
| 1783 | get_user(offset, descr++); |
| 1784 | get_user(data, descr++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1785 | while (nbytes && data) { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1786 | for (i = 0; i < nbytes; i += SX_CHUNK_SIZE) { |
| 1787 | if (copy_from_user(tmp, (char __user *)data + i, |
| 1788 | (i + SX_CHUNK_SIZE > nbytes) ? |
| 1789 | nbytes - i : SX_CHUNK_SIZE)) { |
| 1790 | kfree(tmp); |
Alan Cox | 11af747 | 2008-07-25 01:48:15 -0700 | [diff] [blame] | 1791 | rc = -EFAULT; |
| 1792 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1793 | } |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1794 | memcpy_toio(board->base2 + offset + i, tmp, |
| 1795 | (i + SX_CHUNK_SIZE > nbytes) ? |
| 1796 | nbytes - i : SX_CHUNK_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1797 | } |
| 1798 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1799 | get_user(nbytes, descr++); |
| 1800 | get_user(offset, descr++); |
| 1801 | get_user(data, descr++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1802 | } |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1803 | kfree(tmp); |
| 1804 | sx_nports += sx_init_board(board); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1805 | rc = sx_nports; |
| 1806 | break; |
| 1807 | case SXIO_INIT: |
Alan Cox | 11af747 | 2008-07-25 01:48:15 -0700 | [diff] [blame] | 1808 | if (sx_initialized) { /* Already initialized */ |
| 1809 | rc = -EEXIST; |
| 1810 | break; |
| 1811 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1812 | /* This is not allowed until all boards are initialized... */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1813 | for (i = 0; i < SX_NBOARDS; i++) { |
| 1814 | if ((boards[i].flags & SX_BOARD_PRESENT) && |
Alan Cox | 11af747 | 2008-07-25 01:48:15 -0700 | [diff] [blame] | 1815 | !(boards[i].flags & SX_BOARD_INITIALIZED)) { |
| 1816 | rc = -EIO; |
| 1817 | break; |
| 1818 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1819 | } |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1820 | for (i = 0; i < SX_NBOARDS; i++) |
| 1821 | if (!(boards[i].flags & SX_BOARD_PRESENT)) |
| 1822 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1823 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1824 | sx_dprintk(SX_DEBUG_FIRMWARE, "initing portstructs, %d boards, " |
| 1825 | "%d channels, first board: %d ports\n", |
| 1826 | i, sx_nports, boards[0].nports); |
| 1827 | rc = sx_init_portstructs(i, sx_nports); |
| 1828 | sx_init_drivers(); |
| 1829 | if (rc >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1830 | sx_initialized++; |
| 1831 | break; |
| 1832 | case SXIO_SETDEBUG: |
| 1833 | sx_debug = arg; |
| 1834 | break; |
| 1835 | case SXIO_GETDEBUG: |
| 1836 | rc = sx_debug; |
| 1837 | break; |
| 1838 | case SXIO_GETGSDEBUG: |
| 1839 | case SXIO_SETGSDEBUG: |
| 1840 | rc = -EINVAL; |
| 1841 | break; |
| 1842 | case SXIO_GETNPORTS: |
| 1843 | rc = sx_nports; |
| 1844 | break; |
| 1845 | default: |
Alan Cox | 11af747 | 2008-07-25 01:48:15 -0700 | [diff] [blame] | 1846 | rc = -ENOTTY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1847 | break; |
| 1848 | } |
Dan Carpenter | 736d545 | 2009-02-04 15:12:20 -0800 | [diff] [blame] | 1849 | out: |
Alan Cox | 11af747 | 2008-07-25 01:48:15 -0700 | [diff] [blame] | 1850 | unlock_kernel(); |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1851 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1852 | return rc; |
| 1853 | } |
| 1854 | |
Alan Cox | 9e98966 | 2008-07-22 11:18:03 +0100 | [diff] [blame] | 1855 | static int sx_break(struct tty_struct *tty, int flag) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1856 | { |
| 1857 | struct sx_port *port = tty->driver_data; |
| 1858 | int rv; |
| 1859 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1860 | func_enter(); |
Alan Cox | 341339e | 2008-04-30 00:53:24 -0700 | [diff] [blame] | 1861 | lock_kernel(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1862 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1863 | if (flag) |
| 1864 | rv = sx_send_command(port, HS_START, -1, HS_IDLE_BREAK); |
| 1865 | else |
| 1866 | rv = sx_send_command(port, HS_STOP, -1, HS_IDLE_OPEN); |
| 1867 | if (rv != 1) |
| 1868 | printk(KERN_ERR "sx: couldn't send break (%x).\n", |
| 1869 | read_sx_byte(port->board, CHAN_OFFSET(port, hi_hstat))); |
Alan Cox | 341339e | 2008-04-30 00:53:24 -0700 | [diff] [blame] | 1870 | unlock_kernel(); |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1871 | func_exit(); |
Alan Cox | 9e98966 | 2008-07-22 11:18:03 +0100 | [diff] [blame] | 1872 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1873 | } |
| 1874 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1875 | static int sx_tiocmget(struct tty_struct *tty, struct file *file) |
| 1876 | { |
| 1877 | struct sx_port *port = tty->driver_data; |
| 1878 | return sx_getsignals(port); |
| 1879 | } |
| 1880 | |
| 1881 | static int sx_tiocmset(struct tty_struct *tty, struct file *file, |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1882 | unsigned int set, unsigned int clear) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1883 | { |
| 1884 | struct sx_port *port = tty->driver_data; |
| 1885 | int rts = -1, dtr = -1; |
| 1886 | |
| 1887 | if (set & TIOCM_RTS) |
| 1888 | rts = 1; |
| 1889 | if (set & TIOCM_DTR) |
| 1890 | dtr = 1; |
| 1891 | if (clear & TIOCM_RTS) |
| 1892 | rts = 0; |
| 1893 | if (clear & TIOCM_DTR) |
| 1894 | dtr = 0; |
| 1895 | |
| 1896 | sx_setsignals(port, dtr, rts); |
| 1897 | sx_reconfigure_port(port); |
| 1898 | return 0; |
| 1899 | } |
| 1900 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1901 | static int sx_ioctl(struct tty_struct *tty, struct file *filp, |
| 1902 | unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1903 | { |
| 1904 | int rc; |
| 1905 | struct sx_port *port = tty->driver_data; |
| 1906 | void __user *argp = (void __user *)arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1907 | |
| 1908 | /* func_enter2(); */ |
| 1909 | |
| 1910 | rc = 0; |
Alan Cox | 341339e | 2008-04-30 00:53:24 -0700 | [diff] [blame] | 1911 | lock_kernel(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1912 | switch (cmd) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1913 | case TIOCGSERIAL: |
| 1914 | rc = gs_getserial(&port->gs, argp); |
| 1915 | break; |
| 1916 | case TIOCSSERIAL: |
| 1917 | rc = gs_setserial(&port->gs, argp); |
| 1918 | break; |
| 1919 | default: |
| 1920 | rc = -ENOIOCTLCMD; |
| 1921 | break; |
| 1922 | } |
Alan Cox | 341339e | 2008-04-30 00:53:24 -0700 | [diff] [blame] | 1923 | unlock_kernel(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1924 | |
| 1925 | /* func_exit(); */ |
| 1926 | return rc; |
| 1927 | } |
| 1928 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1929 | /* The throttle/unthrottle scheme for the Specialix card is different |
| 1930 | * from other drivers and deserves some explanation. |
| 1931 | * The Specialix hardware takes care of XON/XOFF |
| 1932 | * and CTS/RTS flow control itself. This means that all we have to |
| 1933 | * do when signalled by the upper tty layer to throttle/unthrottle is |
| 1934 | * to make a note of it here. When we come to read characters from the |
| 1935 | * rx buffers on the card (sx_receive_chars()) we look to see if the |
| 1936 | * upper layer can accept more (as noted here in sx_rx_throt[]). |
| 1937 | * If it can't we simply don't remove chars from the cards buffer. |
| 1938 | * When the tty layer can accept chars, we again note that here and when |
| 1939 | * sx_receive_chars() is called it will remove them from the cards buffer. |
| 1940 | * The card will notice that a ports buffer has drained below some low |
| 1941 | * water mark and will unflow control the line itself, using whatever |
| 1942 | * flow control scheme is in use for that port. -- Simon Allen |
| 1943 | */ |
| 1944 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1945 | static void sx_throttle(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1946 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 1947 | struct sx_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1948 | |
| 1949 | func_enter2(); |
| 1950 | /* If the port is using any type of input flow |
| 1951 | * control then throttle the port. |
| 1952 | */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1953 | if ((tty->termios->c_cflag & CRTSCTS) || (I_IXOFF(tty))) { |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 1954 | port->gs.port.flags |= SX_RX_THROTTLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1955 | } |
| 1956 | func_exit(); |
| 1957 | } |
| 1958 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1959 | static void sx_unthrottle(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1960 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 1961 | struct sx_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1962 | |
| 1963 | func_enter2(); |
| 1964 | /* Always unthrottle even if flow control is not enabled on |
| 1965 | * this port in case we disabled flow control while the port |
| 1966 | * was throttled |
| 1967 | */ |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 1968 | port->gs.port.flags &= ~SX_RX_THROTTLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1969 | func_exit(); |
| 1970 | return; |
| 1971 | } |
| 1972 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1973 | /* ********************************************************************** * |
| 1974 | * Here are the initialization routines. * |
| 1975 | * ********************************************************************** */ |
| 1976 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1977 | static int sx_init_board(struct sx_board *board) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1978 | { |
| 1979 | int addr; |
| 1980 | int chans; |
| 1981 | int type; |
| 1982 | |
| 1983 | func_enter(); |
| 1984 | |
| 1985 | /* This is preceded by downloading the download code. */ |
| 1986 | |
| 1987 | board->flags |= SX_BOARD_INITIALIZED; |
| 1988 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1989 | if (read_sx_byte(board, 0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1990 | /* CF boards may need this. */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1991 | write_sx_byte(board, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1992 | |
| 1993 | /* This resets the processor again, to make sure it didn't do any |
| 1994 | foolish things while we were downloading the image */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1995 | if (!sx_reset(board)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1996 | return 0; |
| 1997 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 1998 | sx_start_board(board); |
| 1999 | udelay(10); |
| 2000 | if (!sx_busy_wait_neq(board, 0, 0xff, 0)) { |
| 2001 | printk(KERN_ERR "sx: Ooops. Board won't initialize.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2002 | return 0; |
| 2003 | } |
| 2004 | |
| 2005 | /* Ok. So now the processor on the card is running. It gathered |
| 2006 | some info for us... */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2007 | sx_dprintk(SX_DEBUG_INIT, "The sxcard structure:\n"); |
| 2008 | if (sx_debug & SX_DEBUG_INIT) |
| 2009 | my_hd_io(board->base, 0x10); |
| 2010 | sx_dprintk(SX_DEBUG_INIT, "the first sx_module structure:\n"); |
| 2011 | if (sx_debug & SX_DEBUG_INIT) |
| 2012 | my_hd_io(board->base + 0x80, 0x30); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2013 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2014 | sx_dprintk(SX_DEBUG_INIT, "init_status: %x, %dk memory, firmware " |
| 2015 | "V%x.%02x,\n", |
| 2016 | read_sx_byte(board, 0), read_sx_byte(board, 1), |
| 2017 | read_sx_byte(board, 5), read_sx_byte(board, 4)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2018 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2019 | if (read_sx_byte(board, 0) == 0xff) { |
| 2020 | printk(KERN_INFO "sx: No modules found. Sorry.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2021 | board->nports = 0; |
| 2022 | return 0; |
| 2023 | } |
| 2024 | |
| 2025 | chans = 0; |
| 2026 | |
| 2027 | if (IS_SX_BOARD(board)) { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2028 | sx_write_board_word(board, cc_int_count, sx_maxints); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2029 | } else { |
| 2030 | if (sx_maxints) |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2031 | sx_write_board_word(board, cc_int_count, |
| 2032 | SI_PROCESSOR_CLOCK / 8 / sx_maxints); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2033 | } |
| 2034 | |
| 2035 | /* grab the first module type... */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2036 | /* board->ta_type = mod_compat_type (read_sx_byte (board, 0x80 + 0x08)); */ |
| 2037 | board->ta_type = mod_compat_type(sx_read_module_byte(board, 0x80, |
| 2038 | mc_chip)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2039 | |
| 2040 | /* XXX byteorder */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2041 | for (addr = 0x80; addr != 0; addr = read_sx_word(board, addr) & 0x7fff){ |
| 2042 | type = sx_read_module_byte(board, addr, mc_chip); |
| 2043 | sx_dprintk(SX_DEBUG_INIT, "Module at %x: %d channels\n", |
| 2044 | addr, read_sx_byte(board, addr + 2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2045 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2046 | chans += sx_read_module_byte(board, addr, mc_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2047 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2048 | sx_dprintk(SX_DEBUG_INIT, "module is an %s, which has %s/%s " |
| 2049 | "panels\n", |
| 2050 | mod_type_s(type), |
| 2051 | pan_type_s(sx_read_module_byte(board, addr, |
| 2052 | mc_mods) & 0xf), |
| 2053 | pan_type_s(sx_read_module_byte(board, addr, |
| 2054 | mc_mods) >> 4)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2055 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2056 | sx_dprintk(SX_DEBUG_INIT, "CD1400 versions: %x/%x, ASIC " |
| 2057 | "version: %x\n", |
| 2058 | sx_read_module_byte(board, addr, mc_rev1), |
| 2059 | sx_read_module_byte(board, addr, mc_rev2), |
| 2060 | sx_read_module_byte(board, addr, mc_mtaasic_rev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2061 | |
| 2062 | /* The following combinations are illegal: It should theoretically |
| 2063 | work, but timing problems make the bus HANG. */ |
| 2064 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2065 | if (mod_compat_type(type) != board->ta_type) { |
| 2066 | printk(KERN_ERR "sx: This is an invalid " |
| 2067 | "configuration.\nDon't mix TA/MTA/SXDC on the " |
| 2068 | "same hostadapter.\n"); |
| 2069 | chans = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2070 | break; |
| 2071 | } |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2072 | if ((IS_EISA_BOARD(board) || |
| 2073 | IS_SI_BOARD(board)) && |
| 2074 | (mod_compat_type(type) == 4)) { |
| 2075 | printk(KERN_ERR "sx: This is an invalid " |
| 2076 | "configuration.\nDon't use SXDCs on an SI/XIO " |
| 2077 | "adapter.\n"); |
| 2078 | chans = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2079 | break; |
| 2080 | } |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2081 | #if 0 /* Problem fixed: firmware 3.05 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2082 | if (IS_SX_BOARD(board) && (type == TA8)) { |
| 2083 | /* There are some issues with the firmware and the DCD/RTS |
| 2084 | lines. It might work if you tie them together or something. |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2085 | It might also work if you get a newer sx_firmware. Therefore |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2086 | this is just a warning. */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2087 | printk(KERN_WARNING |
| 2088 | "sx: The SX host doesn't work too well " |
| 2089 | "with the TA8 adapters.\nSpecialix is working on it.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2090 | } |
| 2091 | #endif |
| 2092 | } |
| 2093 | |
| 2094 | if (chans) { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2095 | if (board->irq > 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2096 | /* fixed irq, probably PCI */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2097 | if (sx_irqmask & (1 << board->irq)) { /* may we use this irq? */ |
| 2098 | if (request_irq(board->irq, sx_interrupt, |
| 2099 | IRQF_SHARED | IRQF_DISABLED, |
| 2100 | "sx", board)) { |
| 2101 | printk(KERN_ERR "sx: Cannot allocate " |
| 2102 | "irq %d.\n", board->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2103 | board->irq = 0; |
| 2104 | } |
| 2105 | } else |
| 2106 | board->irq = 0; |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2107 | } else if (board->irq < 0 && sx_irqmask) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2108 | /* auto-allocate irq */ |
| 2109 | int irqnr; |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2110 | int irqmask = sx_irqmask & (IS_SX_BOARD(board) ? |
| 2111 | SX_ISA_IRQ_MASK : SI2_ISA_IRQ_MASK); |
| 2112 | for (irqnr = 15; irqnr > 0; irqnr--) |
| 2113 | if (irqmask & (1 << irqnr)) |
| 2114 | if (!request_irq(irqnr, sx_interrupt, |
| 2115 | IRQF_SHARED | IRQF_DISABLED, |
| 2116 | "sx", board)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2117 | break; |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2118 | if (!irqnr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2119 | printk(KERN_ERR "sx: Cannot allocate IRQ.\n"); |
| 2120 | board->irq = irqnr; |
| 2121 | } else |
| 2122 | board->irq = 0; |
| 2123 | |
| 2124 | if (board->irq) { |
| 2125 | /* Found a valid interrupt, start up interrupts! */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2126 | sx_dprintk(SX_DEBUG_INIT, "Using irq %d.\n", |
| 2127 | board->irq); |
| 2128 | sx_start_interrupts(board); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2129 | board->poll = sx_slowpoll; |
| 2130 | board->flags |= SX_IRQ_ALLOCATED; |
| 2131 | } else { |
| 2132 | /* no irq: setup board for polled operation */ |
| 2133 | board->poll = sx_poll; |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2134 | sx_dprintk(SX_DEBUG_INIT, "Using poll-interval %d.\n", |
| 2135 | board->poll); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2136 | } |
| 2137 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2138 | /* The timer should be initialized anyway: That way we can |
| 2139 | safely del_timer it when the module is unloaded. */ |
Jiri Slaby | c959464 | 2006-12-08 02:39:05 -0800 | [diff] [blame] | 2140 | setup_timer(&board->timer, sx_pollfunc, (unsigned long)board); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2141 | |
Jiri Slaby | c959464 | 2006-12-08 02:39:05 -0800 | [diff] [blame] | 2142 | if (board->poll) |
| 2143 | mod_timer(&board->timer, jiffies + board->poll); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2144 | } else { |
| 2145 | board->irq = 0; |
| 2146 | } |
| 2147 | |
| 2148 | board->nports = chans; |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2149 | sx_dprintk(SX_DEBUG_INIT, "returning %d ports.", board->nports); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2150 | |
| 2151 | func_exit(); |
| 2152 | return chans; |
| 2153 | } |
| 2154 | |
Jiri Slaby | cda5265 | 2006-12-08 02:39:00 -0800 | [diff] [blame] | 2155 | static void __devinit printheader(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2156 | { |
| 2157 | static int header_printed; |
| 2158 | |
| 2159 | if (!header_printed) { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2160 | printk(KERN_INFO "Specialix SX driver " |
| 2161 | "(C) 1998/1999 R.E.Wolff@BitWizard.nl\n"); |
| 2162 | printk(KERN_INFO "sx: version " __stringify(SX_VERSION) "\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2163 | header_printed = 1; |
| 2164 | } |
| 2165 | } |
| 2166 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2167 | static int __devinit probe_sx(struct sx_board *board) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2168 | { |
| 2169 | struct vpd_prom vpdp; |
| 2170 | char *p; |
| 2171 | int i; |
| 2172 | |
| 2173 | func_enter(); |
| 2174 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2175 | if (!IS_CF_BOARD(board)) { |
| 2176 | sx_dprintk(SX_DEBUG_PROBE, "Going to verify vpd prom at %p.\n", |
| 2177 | board->base + SX_VPD_ROM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2178 | |
| 2179 | if (sx_debug & SX_DEBUG_PROBE) |
| 2180 | my_hd_io(board->base + SX_VPD_ROM, 0x40); |
| 2181 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2182 | p = (char *)&vpdp; |
| 2183 | for (i = 0; i < sizeof(struct vpd_prom); i++) |
| 2184 | *p++ = read_sx_byte(board, SX_VPD_ROM + i * 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2185 | |
| 2186 | if (sx_debug & SX_DEBUG_PROBE) |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2187 | my_hd(&vpdp, 0x20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2188 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2189 | sx_dprintk(SX_DEBUG_PROBE, "checking identifier...\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2190 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2191 | if (strncmp(vpdp.identifier, SX_VPD_IDENT_STRING, 16) != 0) { |
| 2192 | sx_dprintk(SX_DEBUG_PROBE, "Got non-SX identifier: " |
| 2193 | "'%s'\n", vpdp.identifier); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2194 | return 0; |
| 2195 | } |
| 2196 | } |
| 2197 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2198 | printheader(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2199 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2200 | if (!IS_CF_BOARD(board)) { |
| 2201 | printk(KERN_DEBUG "sx: Found an SX board at %lx\n", |
| 2202 | board->hw_base); |
| 2203 | printk(KERN_DEBUG "sx: hw_rev: %d, assembly level: %d, " |
| 2204 | "uniq ID:%08x, ", |
| 2205 | vpdp.hwrev, vpdp.hwass, vpdp.uniqid); |
| 2206 | printk("Manufactured: %d/%d\n", 1970 + vpdp.myear, vpdp.mweek); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2207 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2208 | if ((((vpdp.uniqid >> 24) & SX_UNIQUEID_MASK) != |
| 2209 | SX_PCI_UNIQUEID1) && (((vpdp.uniqid >> 24) & |
| 2210 | SX_UNIQUEID_MASK) != SX_ISA_UNIQUEID1)) { |
| 2211 | /* This might be a bit harsh. This was the primary |
| 2212 | reason the SX/ISA card didn't work at first... */ |
| 2213 | printk(KERN_ERR "sx: Hmm. Not an SX/PCI or SX/ISA " |
| 2214 | "card. Sorry: giving up.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2215 | return (0); |
| 2216 | } |
| 2217 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2218 | if (((vpdp.uniqid >> 24) & SX_UNIQUEID_MASK) == |
| 2219 | SX_ISA_UNIQUEID1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2220 | if (((unsigned long)board->hw_base) & 0x8000) { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2221 | printk(KERN_WARNING "sx: Warning: There may be " |
| 2222 | "hardware problems with the card at " |
| 2223 | "%lx.\n", board->hw_base); |
| 2224 | printk(KERN_WARNING "sx: Read sx.txt for more " |
| 2225 | "info.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2226 | } |
| 2227 | } |
| 2228 | } |
| 2229 | |
| 2230 | board->nports = -1; |
| 2231 | |
| 2232 | /* This resets the processor, and keeps it off the bus. */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2233 | if (!sx_reset(board)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2234 | return 0; |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2235 | sx_dprintk(SX_DEBUG_INIT, "reset the board...\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2236 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2237 | func_exit(); |
| 2238 | return 1; |
| 2239 | } |
| 2240 | |
Jiri Slaby | 927a6f9 | 2006-12-08 02:39:02 -0800 | [diff] [blame] | 2241 | #if defined(CONFIG_ISA) || defined(CONFIG_EISA) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2242 | |
| 2243 | /* Specialix probes for this card at 32k increments from 640k to 16M. |
| 2244 | I consider machines with less than 16M unlikely nowadays, so I'm |
| 2245 | not probing above 1Mb. Also, 0xa0000, 0xb0000, are taken by the VGA |
| 2246 | card. 0xe0000 and 0xf0000 are taken by the BIOS. That only leaves |
| 2247 | 0xc0000, 0xc8000, 0xd0000 and 0xd8000 . */ |
| 2248 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2249 | static int __devinit probe_si(struct sx_board *board) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2250 | { |
| 2251 | int i; |
| 2252 | |
| 2253 | func_enter(); |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2254 | sx_dprintk(SX_DEBUG_PROBE, "Going to verify SI signature hw %lx at " |
| 2255 | "%p.\n", board->hw_base, board->base + SI2_ISA_ID_BASE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2256 | |
| 2257 | if (sx_debug & SX_DEBUG_PROBE) |
| 2258 | my_hd_io(board->base + SI2_ISA_ID_BASE, 0x8); |
| 2259 | |
| 2260 | if (!IS_EISA_BOARD(board)) { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2261 | if (IS_SI1_BOARD(board)) { |
| 2262 | for (i = 0; i < 8; i++) { |
| 2263 | write_sx_byte(board, SI2_ISA_ID_BASE + 7 - i,i); |
| 2264 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2265 | } |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2266 | for (i = 0; i < 8; i++) { |
| 2267 | if ((read_sx_byte(board, SI2_ISA_ID_BASE + 7 - i) & 7) |
| 2268 | != i) { |
| 2269 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2270 | return 0; |
| 2271 | } |
| 2272 | } |
| 2273 | } |
| 2274 | |
| 2275 | /* Now we're pretty much convinced that there is an SI board here, |
| 2276 | but to prevent trouble, we'd better double check that we don't |
| 2277 | have an SI1 board when we're probing for an SI2 board.... */ |
| 2278 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2279 | write_sx_byte(board, SI2_ISA_ID_BASE, 0x10); |
| 2280 | if (IS_SI1_BOARD(board)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2281 | /* This should be an SI1 board, which has this |
| 2282 | location writable... */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2283 | if (read_sx_byte(board, SI2_ISA_ID_BASE) != 0x10) { |
| 2284 | func_exit(); |
| 2285 | return 0; |
Marc Zyngier | 04a3d31 | 2006-02-26 12:02:56 +0100 | [diff] [blame] | 2286 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2287 | } else { |
| 2288 | /* This should be an SI2 board, which has the bottom |
| 2289 | 3 bits non-writable... */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2290 | if (read_sx_byte(board, SI2_ISA_ID_BASE) == 0x10) { |
| 2291 | func_exit(); |
| 2292 | return 0; |
Marc Zyngier | 04a3d31 | 2006-02-26 12:02:56 +0100 | [diff] [blame] | 2293 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2294 | } |
| 2295 | |
| 2296 | /* Now we're pretty much convinced that there is an SI board here, |
| 2297 | but to prevent trouble, we'd better double check that we don't |
| 2298 | have an SI1 board when we're probing for an SI2 board.... */ |
| 2299 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2300 | write_sx_byte(board, SI2_ISA_ID_BASE, 0x10); |
| 2301 | if (IS_SI1_BOARD(board)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2302 | /* This should be an SI1 board, which has this |
| 2303 | location writable... */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2304 | if (read_sx_byte(board, SI2_ISA_ID_BASE) != 0x10) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2305 | func_exit(); |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2306 | return 0; |
Marc Zyngier | 04a3d31 | 2006-02-26 12:02:56 +0100 | [diff] [blame] | 2307 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2308 | } else { |
| 2309 | /* This should be an SI2 board, which has the bottom |
| 2310 | 3 bits non-writable... */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2311 | if (read_sx_byte(board, SI2_ISA_ID_BASE) == 0x10) { |
| 2312 | func_exit(); |
| 2313 | return 0; |
Marc Zyngier | 04a3d31 | 2006-02-26 12:02:56 +0100 | [diff] [blame] | 2314 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2315 | } |
| 2316 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2317 | printheader(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2318 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2319 | printk(KERN_DEBUG "sx: Found an SI board at %lx\n", board->hw_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2320 | /* Compared to the SX boards, it is a complete guess as to what |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2321 | this card is up to... */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2322 | |
| 2323 | board->nports = -1; |
| 2324 | |
| 2325 | /* This resets the processor, and keeps it off the bus. */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2326 | if (!sx_reset(board)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2327 | return 0; |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2328 | sx_dprintk(SX_DEBUG_INIT, "reset the board...\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2329 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2330 | func_exit(); |
| 2331 | return 1; |
| 2332 | } |
Jiri Slaby | 927a6f9 | 2006-12-08 02:39:02 -0800 | [diff] [blame] | 2333 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2334 | |
Jeff Dike | b68e31d | 2006-10-02 02:17:18 -0700 | [diff] [blame] | 2335 | static const struct tty_operations sx_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2336 | .break_ctl = sx_break, |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2337 | .open = sx_open, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2338 | .close = gs_close, |
| 2339 | .write = gs_write, |
| 2340 | .put_char = gs_put_char, |
| 2341 | .flush_chars = gs_flush_chars, |
| 2342 | .write_room = gs_write_room, |
| 2343 | .chars_in_buffer = gs_chars_in_buffer, |
| 2344 | .flush_buffer = gs_flush_buffer, |
| 2345 | .ioctl = sx_ioctl, |
| 2346 | .throttle = sx_throttle, |
| 2347 | .unthrottle = sx_unthrottle, |
| 2348 | .set_termios = gs_set_termios, |
| 2349 | .stop = gs_stop, |
| 2350 | .start = gs_start, |
| 2351 | .hangup = gs_hangup, |
| 2352 | .tiocmget = sx_tiocmget, |
| 2353 | .tiocmset = sx_tiocmset, |
| 2354 | }; |
| 2355 | |
Alan Cox | 31f3593 | 2009-01-02 13:45:05 +0000 | [diff] [blame] | 2356 | static const struct tty_port_operations sx_port_ops = { |
| 2357 | .carrier_raised = sx_carrier_raised, |
| 2358 | }; |
| 2359 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2360 | static int sx_init_drivers(void) |
| 2361 | { |
| 2362 | int error; |
| 2363 | |
| 2364 | func_enter(); |
| 2365 | |
| 2366 | sx_driver = alloc_tty_driver(sx_nports); |
| 2367 | if (!sx_driver) |
| 2368 | return 1; |
| 2369 | sx_driver->owner = THIS_MODULE; |
| 2370 | sx_driver->driver_name = "specialix_sx"; |
| 2371 | sx_driver->name = "ttyX"; |
| 2372 | sx_driver->major = SX_NORMAL_MAJOR; |
| 2373 | sx_driver->type = TTY_DRIVER_TYPE_SERIAL; |
| 2374 | sx_driver->subtype = SERIAL_TYPE_NORMAL; |
| 2375 | sx_driver->init_termios = tty_std_termios; |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2376 | sx_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 2377 | sx_driver->init_termios.c_ispeed = 9600; |
| 2378 | sx_driver->init_termios.c_ospeed = 9600; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2379 | sx_driver->flags = TTY_DRIVER_REAL_RAW; |
| 2380 | tty_set_operations(sx_driver, &sx_ops); |
| 2381 | |
| 2382 | if ((error = tty_register_driver(sx_driver))) { |
| 2383 | put_tty_driver(sx_driver); |
| 2384 | printk(KERN_ERR "sx: Couldn't register sx driver, error = %d\n", |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2385 | error); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2386 | return 1; |
| 2387 | } |
| 2388 | func_exit(); |
| 2389 | return 0; |
| 2390 | } |
| 2391 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2392 | static int sx_init_portstructs(int nboards, int nports) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2393 | { |
| 2394 | struct sx_board *board; |
| 2395 | struct sx_port *port; |
| 2396 | int i, j; |
| 2397 | int addr, chans; |
| 2398 | int portno; |
| 2399 | |
| 2400 | func_enter(); |
| 2401 | |
| 2402 | /* Many drivers statically allocate the maximum number of ports |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2403 | There is no reason not to allocate them dynamically. |
| 2404 | Is there? -- REW */ |
Jiri Slaby | 4a7cb69 | 2006-12-08 02:38:59 -0800 | [diff] [blame] | 2405 | sx_ports = kcalloc(nports, sizeof(struct sx_port), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2406 | if (!sx_ports) |
| 2407 | return -ENOMEM; |
| 2408 | |
| 2409 | port = sx_ports; |
| 2410 | for (i = 0; i < nboards; i++) { |
| 2411 | board = &boards[i]; |
| 2412 | board->ports = port; |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2413 | for (j = 0; j < boards[i].nports; j++) { |
| 2414 | sx_dprintk(SX_DEBUG_INIT, "initing port %d\n", j); |
Alan Cox | 44b7d1b | 2008-07-16 21:57:18 +0100 | [diff] [blame] | 2415 | tty_port_init(&port->gs.port); |
Alan Cox | 31f3593 | 2009-01-02 13:45:05 +0000 | [diff] [blame] | 2416 | port->gs.port.ops = &sx_port_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2417 | port->gs.magic = SX_MAGIC; |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2418 | port->gs.close_delay = HZ / 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2419 | port->gs.closing_wait = 30 * HZ; |
| 2420 | port->board = board; |
| 2421 | port->gs.rd = &sx_real_driver; |
| 2422 | #ifdef NEW_WRITE_LOCKING |
Ingo Molnar | 81861d7 | 2006-03-23 03:00:44 -0800 | [diff] [blame] | 2423 | port->gs.port_write_mutex = MUTEX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2424 | #endif |
Ingo Molnar | 34af946 | 2006-06-27 02:53:55 -0700 | [diff] [blame] | 2425 | spin_lock_init(&port->gs.driver_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2426 | /* |
| 2427 | * Initializing wait queue |
| 2428 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2429 | port++; |
| 2430 | } |
| 2431 | } |
| 2432 | |
| 2433 | port = sx_ports; |
| 2434 | portno = 0; |
| 2435 | for (i = 0; i < nboards; i++) { |
| 2436 | board = &boards[i]; |
| 2437 | board->port_base = portno; |
| 2438 | /* Possibly the configuration was rejected. */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2439 | sx_dprintk(SX_DEBUG_PROBE, "Board has %d channels\n", |
| 2440 | board->nports); |
| 2441 | if (board->nports <= 0) |
| 2442 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2443 | /* XXX byteorder ?? */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2444 | for (addr = 0x80; addr != 0; |
| 2445 | addr = read_sx_word(board, addr) & 0x7fff) { |
| 2446 | chans = sx_read_module_byte(board, addr, mc_type); |
| 2447 | sx_dprintk(SX_DEBUG_PROBE, "Module at %x: %d " |
| 2448 | "channels\n", addr, chans); |
| 2449 | sx_dprintk(SX_DEBUG_PROBE, "Port at"); |
| 2450 | for (j = 0; j < chans; j++) { |
| 2451 | /* The "sx-way" is the way it SHOULD be done. |
| 2452 | That way in the future, the firmware may for |
| 2453 | example pack the structures a bit more |
| 2454 | efficient. Neil tells me it isn't going to |
| 2455 | happen anytime soon though. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2456 | if (IS_SX_BOARD(board)) |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2457 | port->ch_base = sx_read_module_word( |
| 2458 | board, addr + j * 2, |
| 2459 | mc_chan_pointer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2460 | else |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2461 | port->ch_base = addr + 0x100 + 0x300 *j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2462 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2463 | sx_dprintk(SX_DEBUG_PROBE, " %x", |
| 2464 | port->ch_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2465 | port->line = portno++; |
| 2466 | port++; |
| 2467 | } |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2468 | sx_dprintk(SX_DEBUG_PROBE, "\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2469 | } |
| 2470 | /* This has to be done earlier. */ |
| 2471 | /* board->flags |= SX_BOARD_INITIALIZED; */ |
| 2472 | } |
| 2473 | |
| 2474 | func_exit(); |
| 2475 | return 0; |
| 2476 | } |
| 2477 | |
Jiri Slaby | 18f813e | 2006-12-08 02:39:01 -0800 | [diff] [blame] | 2478 | static unsigned int sx_find_free_board(void) |
| 2479 | { |
| 2480 | unsigned int i; |
| 2481 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2482 | for (i = 0; i < SX_NBOARDS; i++) |
Jiri Slaby | 18f813e | 2006-12-08 02:39:01 -0800 | [diff] [blame] | 2483 | if (!(boards[i].flags & SX_BOARD_PRESENT)) |
| 2484 | break; |
| 2485 | |
| 2486 | return i; |
| 2487 | } |
| 2488 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2489 | static void __exit sx_release_drivers(void) |
| 2490 | { |
| 2491 | func_enter(); |
| 2492 | tty_unregister_driver(sx_driver); |
| 2493 | put_tty_driver(sx_driver); |
| 2494 | func_exit(); |
| 2495 | } |
| 2496 | |
Jiri Slaby | 3910349 | 2006-12-08 02:39:07 -0800 | [diff] [blame] | 2497 | static void __devexit sx_remove_card(struct sx_board *board, |
| 2498 | struct pci_dev *pdev) |
Jiri Slaby | 18f813e | 2006-12-08 02:39:01 -0800 | [diff] [blame] | 2499 | { |
| 2500 | if (board->flags & SX_BOARD_INITIALIZED) { |
| 2501 | /* The board should stop messing with us. (actually I mean the |
| 2502 | interrupt) */ |
| 2503 | sx_reset(board); |
| 2504 | if ((board->irq) && (board->flags & SX_IRQ_ALLOCATED)) |
| 2505 | free_irq(board->irq, board); |
| 2506 | |
| 2507 | /* It is safe/allowed to del_timer a non-active timer */ |
| 2508 | del_timer(&board->timer); |
Jiri Slaby | 30f4218 | 2006-12-08 02:39:08 -0800 | [diff] [blame] | 2509 | if (pdev) { |
Jiri Slaby | 3468a33 | 2006-12-13 00:34:20 -0800 | [diff] [blame] | 2510 | #ifdef CONFIG_PCI |
Jiri Slaby | da1cfe1 | 2008-10-18 20:27:44 -0700 | [diff] [blame] | 2511 | iounmap(board->base2); |
Jiri Slaby | 30f4218 | 2006-12-08 02:39:08 -0800 | [diff] [blame] | 2512 | pci_release_region(pdev, IS_CF_BOARD(board) ? 3 : 2); |
Jiri Slaby | 3468a33 | 2006-12-13 00:34:20 -0800 | [diff] [blame] | 2513 | #endif |
Jiri Slaby | 30f4218 | 2006-12-08 02:39:08 -0800 | [diff] [blame] | 2514 | } else { |
Jiri Slaby | 3910349 | 2006-12-08 02:39:07 -0800 | [diff] [blame] | 2515 | iounmap(board->base); |
Jiri Slaby | 30f4218 | 2006-12-08 02:39:08 -0800 | [diff] [blame] | 2516 | release_region(board->hw_base, board->hw_len); |
| 2517 | } |
Jiri Slaby | 18f813e | 2006-12-08 02:39:01 -0800 | [diff] [blame] | 2518 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2519 | board->flags &= ~(SX_BOARD_INITIALIZED | SX_BOARD_PRESENT); |
Jiri Slaby | 18f813e | 2006-12-08 02:39:01 -0800 | [diff] [blame] | 2520 | } |
| 2521 | } |
| 2522 | |
| 2523 | #ifdef CONFIG_EISA |
| 2524 | |
| 2525 | static int __devinit sx_eisa_probe(struct device *dev) |
| 2526 | { |
| 2527 | struct eisa_device *edev = to_eisa_device(dev); |
| 2528 | struct sx_board *board; |
| 2529 | unsigned long eisa_slot = edev->base_addr; |
| 2530 | unsigned int i; |
| 2531 | int retval = -EIO; |
| 2532 | |
Jiri Slaby | 42f6384 | 2006-12-08 02:39:03 -0800 | [diff] [blame] | 2533 | mutex_lock(&sx_boards_lock); |
Jiri Slaby | 18f813e | 2006-12-08 02:39:01 -0800 | [diff] [blame] | 2534 | i = sx_find_free_board(); |
Jiri Slaby | 42f6384 | 2006-12-08 02:39:03 -0800 | [diff] [blame] | 2535 | if (i == SX_NBOARDS) { |
| 2536 | mutex_unlock(&sx_boards_lock); |
Jiri Slaby | 18f813e | 2006-12-08 02:39:01 -0800 | [diff] [blame] | 2537 | goto err; |
Jiri Slaby | 42f6384 | 2006-12-08 02:39:03 -0800 | [diff] [blame] | 2538 | } |
| 2539 | board = &boards[i]; |
| 2540 | board->flags |= SX_BOARD_PRESENT; |
| 2541 | mutex_unlock(&sx_boards_lock); |
Jiri Slaby | 18f813e | 2006-12-08 02:39:01 -0800 | [diff] [blame] | 2542 | |
| 2543 | dev_info(dev, "XIO : Signature found in EISA slot %lu, " |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2544 | "Product %d Rev %d (REPORT THIS TO LKLM)\n", |
| 2545 | eisa_slot >> 12, |
| 2546 | inb(eisa_slot + EISA_VENDOR_ID_OFFSET + 2), |
| 2547 | inb(eisa_slot + EISA_VENDOR_ID_OFFSET + 3)); |
Jiri Slaby | 18f813e | 2006-12-08 02:39:01 -0800 | [diff] [blame] | 2548 | |
Jiri Slaby | 18f813e | 2006-12-08 02:39:01 -0800 | [diff] [blame] | 2549 | board->eisa_base = eisa_slot; |
| 2550 | board->flags &= ~SX_BOARD_TYPE; |
| 2551 | board->flags |= SI_EISA_BOARD; |
| 2552 | |
| 2553 | board->hw_base = ((inb(eisa_slot + 0xc01) << 8) + |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2554 | inb(eisa_slot + 0xc00)) << 16; |
Jiri Slaby | 30f4218 | 2006-12-08 02:39:08 -0800 | [diff] [blame] | 2555 | board->hw_len = SI2_EISA_WINDOW_LEN; |
| 2556 | if (!request_region(board->hw_base, board->hw_len, "sx")) { |
| 2557 | dev_err(dev, "can't request region\n"); |
| 2558 | goto err_flag; |
| 2559 | } |
Jiri Slaby | 18f813e | 2006-12-08 02:39:01 -0800 | [diff] [blame] | 2560 | board->base2 = |
Alan Cox | 24cb233 | 2008-04-30 00:54:19 -0700 | [diff] [blame] | 2561 | board->base = ioremap_nocache(board->hw_base, SI2_EISA_WINDOW_LEN); |
Jiri Slaby | 30f4218 | 2006-12-08 02:39:08 -0800 | [diff] [blame] | 2562 | if (!board->base) { |
| 2563 | dev_err(dev, "can't remap memory\n"); |
| 2564 | goto err_reg; |
| 2565 | } |
Jiri Slaby | 18f813e | 2006-12-08 02:39:01 -0800 | [diff] [blame] | 2566 | |
| 2567 | sx_dprintk(SX_DEBUG_PROBE, "IO hw_base address: %lx\n", board->hw_base); |
| 2568 | sx_dprintk(SX_DEBUG_PROBE, "base: %p\n", board->base); |
| 2569 | board->irq = inb(eisa_slot + 0xc02) >> 4; |
| 2570 | sx_dprintk(SX_DEBUG_PROBE, "IRQ: %d\n", board->irq); |
| 2571 | |
| 2572 | if (!probe_si(board)) |
| 2573 | goto err_unmap; |
| 2574 | |
| 2575 | dev_set_drvdata(dev, board); |
| 2576 | |
| 2577 | return 0; |
| 2578 | err_unmap: |
| 2579 | iounmap(board->base); |
Jiri Slaby | 30f4218 | 2006-12-08 02:39:08 -0800 | [diff] [blame] | 2580 | err_reg: |
| 2581 | release_region(board->hw_base, board->hw_len); |
| 2582 | err_flag: |
Jiri Slaby | 42f6384 | 2006-12-08 02:39:03 -0800 | [diff] [blame] | 2583 | board->flags &= ~SX_BOARD_PRESENT; |
Jiri Slaby | 18f813e | 2006-12-08 02:39:01 -0800 | [diff] [blame] | 2584 | err: |
| 2585 | return retval; |
| 2586 | } |
| 2587 | |
| 2588 | static int __devexit sx_eisa_remove(struct device *dev) |
| 2589 | { |
| 2590 | struct sx_board *board = dev_get_drvdata(dev); |
| 2591 | |
Jiri Slaby | 3910349 | 2006-12-08 02:39:07 -0800 | [diff] [blame] | 2592 | sx_remove_card(board, NULL); |
Jiri Slaby | 18f813e | 2006-12-08 02:39:01 -0800 | [diff] [blame] | 2593 | |
| 2594 | return 0; |
| 2595 | } |
| 2596 | |
| 2597 | static struct eisa_device_id sx_eisa_tbl[] = { |
| 2598 | { "SLX" }, |
| 2599 | { "" } |
| 2600 | }; |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2601 | |
Jiri Slaby | 18f813e | 2006-12-08 02:39:01 -0800 | [diff] [blame] | 2602 | MODULE_DEVICE_TABLE(eisa, sx_eisa_tbl); |
| 2603 | |
| 2604 | static struct eisa_driver sx_eisadriver = { |
| 2605 | .id_table = sx_eisa_tbl, |
| 2606 | .driver = { |
| 2607 | .name = "sx", |
| 2608 | .probe = sx_eisa_probe, |
| 2609 | .remove = __devexit_p(sx_eisa_remove), |
| 2610 | } |
| 2611 | }; |
| 2612 | |
| 2613 | #endif |
| 2614 | |
Jiri Slaby | 3468a33 | 2006-12-13 00:34:20 -0800 | [diff] [blame] | 2615 | #ifdef CONFIG_PCI |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2616 | /******************************************************** |
| 2617 | * Setting bit 17 in the CNTRL register of the PLX 9050 * |
| 2618 | * chip forces a retry on writes while a read is pending.* |
| 2619 | * This is to prevent the card locking up on Intel Xeon * |
| 2620 | * multiprocessor systems with the NX chipset. -- NV * |
| 2621 | ********************************************************/ |
| 2622 | |
| 2623 | /* Newer cards are produced with this bit set from the configuration |
| 2624 | EEprom. As the bit is read/write for the CPU, we can fix it here, |
| 2625 | if we detect that it isn't set correctly. -- REW */ |
| 2626 | |
Jiri Slaby | cda5265 | 2006-12-08 02:39:00 -0800 | [diff] [blame] | 2627 | static void __devinit fix_sx_pci(struct pci_dev *pdev, struct sx_board *board) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2628 | { |
| 2629 | unsigned int hwbase; |
| 2630 | void __iomem *rebase; |
| 2631 | unsigned int t; |
| 2632 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2633 | #define CNTRL_REG_OFFSET 0x50 |
| 2634 | #define CNTRL_REG_GOODVALUE 0x18260000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2635 | |
| 2636 | pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &hwbase); |
| 2637 | hwbase &= PCI_BASE_ADDRESS_MEM_MASK; |
Alan Cox | 24cb233 | 2008-04-30 00:54:19 -0700 | [diff] [blame] | 2638 | rebase = ioremap_nocache(hwbase, 0x80); |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2639 | t = readl(rebase + CNTRL_REG_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2640 | if (t != CNTRL_REG_GOODVALUE) { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2641 | printk(KERN_DEBUG "sx: performing cntrl reg fix: %08x -> " |
| 2642 | "%08x\n", t, CNTRL_REG_GOODVALUE); |
| 2643 | writel(CNTRL_REG_GOODVALUE, rebase + CNTRL_REG_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2644 | } |
| 2645 | iounmap(rebase); |
| 2646 | } |
Jiri Slaby | 3468a33 | 2006-12-13 00:34:20 -0800 | [diff] [blame] | 2647 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2648 | |
Jiri Slaby | 5572e10 | 2006-12-08 02:38:58 -0800 | [diff] [blame] | 2649 | static int __devinit sx_pci_probe(struct pci_dev *pdev, |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2650 | const struct pci_device_id *ent) |
Jiri Slaby | 5572e10 | 2006-12-08 02:38:58 -0800 | [diff] [blame] | 2651 | { |
Jiri Slaby | 3468a33 | 2006-12-13 00:34:20 -0800 | [diff] [blame] | 2652 | #ifdef CONFIG_PCI |
Jiri Slaby | 5572e10 | 2006-12-08 02:38:58 -0800 | [diff] [blame] | 2653 | struct sx_board *board; |
Jiri Slaby | 3910349 | 2006-12-08 02:39:07 -0800 | [diff] [blame] | 2654 | unsigned int i, reg; |
Jiri Slaby | 5572e10 | 2006-12-08 02:38:58 -0800 | [diff] [blame] | 2655 | int retval = -EIO; |
| 2656 | |
Jiri Slaby | 42f6384 | 2006-12-08 02:39:03 -0800 | [diff] [blame] | 2657 | mutex_lock(&sx_boards_lock); |
Jiri Slaby | 18f813e | 2006-12-08 02:39:01 -0800 | [diff] [blame] | 2658 | i = sx_find_free_board(); |
Jiri Slaby | 42f6384 | 2006-12-08 02:39:03 -0800 | [diff] [blame] | 2659 | if (i == SX_NBOARDS) { |
| 2660 | mutex_unlock(&sx_boards_lock); |
Jiri Slaby | 5572e10 | 2006-12-08 02:38:58 -0800 | [diff] [blame] | 2661 | goto err; |
Jiri Slaby | 42f6384 | 2006-12-08 02:39:03 -0800 | [diff] [blame] | 2662 | } |
| 2663 | board = &boards[i]; |
| 2664 | board->flags |= SX_BOARD_PRESENT; |
| 2665 | mutex_unlock(&sx_boards_lock); |
Jiri Slaby | 5572e10 | 2006-12-08 02:38:58 -0800 | [diff] [blame] | 2666 | |
| 2667 | retval = pci_enable_device(pdev); |
| 2668 | if (retval) |
Jiri Slaby | 42f6384 | 2006-12-08 02:39:03 -0800 | [diff] [blame] | 2669 | goto err_flag; |
Jiri Slaby | 5572e10 | 2006-12-08 02:38:58 -0800 | [diff] [blame] | 2670 | |
| 2671 | board->flags &= ~SX_BOARD_TYPE; |
| 2672 | board->flags |= (pdev->subsystem_vendor == 0x200) ? SX_PCI_BOARD : |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2673 | SX_CFPCI_BOARD; |
Jiri Slaby | 5572e10 | 2006-12-08 02:38:58 -0800 | [diff] [blame] | 2674 | |
| 2675 | /* CF boards use base address 3.... */ |
Jiri Slaby | 3910349 | 2006-12-08 02:39:07 -0800 | [diff] [blame] | 2676 | reg = IS_CF_BOARD(board) ? 3 : 2; |
Jiri Slaby | 30f4218 | 2006-12-08 02:39:08 -0800 | [diff] [blame] | 2677 | retval = pci_request_region(pdev, reg, "sx"); |
| 2678 | if (retval) { |
| 2679 | dev_err(&pdev->dev, "can't request region\n"); |
| 2680 | goto err_flag; |
| 2681 | } |
Jiri Slaby | 3910349 | 2006-12-08 02:39:07 -0800 | [diff] [blame] | 2682 | board->hw_base = pci_resource_start(pdev, reg); |
Jiri Slaby | 5572e10 | 2006-12-08 02:38:58 -0800 | [diff] [blame] | 2683 | board->base2 = |
Jiri Slaby | da1cfe1 | 2008-10-18 20:27:44 -0700 | [diff] [blame] | 2684 | board->base = ioremap_nocache(board->hw_base, WINDOW_LEN(board)); |
Jiri Slaby | 5572e10 | 2006-12-08 02:38:58 -0800 | [diff] [blame] | 2685 | if (!board->base) { |
| 2686 | dev_err(&pdev->dev, "ioremap failed\n"); |
Jiri Slaby | 30f4218 | 2006-12-08 02:39:08 -0800 | [diff] [blame] | 2687 | goto err_reg; |
Jiri Slaby | 5572e10 | 2006-12-08 02:38:58 -0800 | [diff] [blame] | 2688 | } |
| 2689 | |
| 2690 | /* Most of the stuff on the CF board is offset by 0x18000 .... */ |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2691 | if (IS_CF_BOARD(board)) |
Jiri Slaby | 5572e10 | 2006-12-08 02:38:58 -0800 | [diff] [blame] | 2692 | board->base += 0x18000; |
| 2693 | |
| 2694 | board->irq = pdev->irq; |
| 2695 | |
| 2696 | dev_info(&pdev->dev, "Got a specialix card: %p(%d) %x.\n", board->base, |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2697 | board->irq, board->flags); |
Jiri Slaby | 5572e10 | 2006-12-08 02:38:58 -0800 | [diff] [blame] | 2698 | |
| 2699 | if (!probe_sx(board)) { |
| 2700 | retval = -EIO; |
| 2701 | goto err_unmap; |
| 2702 | } |
| 2703 | |
| 2704 | fix_sx_pci(pdev, board); |
| 2705 | |
| 2706 | pci_set_drvdata(pdev, board); |
| 2707 | |
| 2708 | return 0; |
| 2709 | err_unmap: |
Jiri Slaby | da1cfe1 | 2008-10-18 20:27:44 -0700 | [diff] [blame] | 2710 | iounmap(board->base2); |
Jiri Slaby | 30f4218 | 2006-12-08 02:39:08 -0800 | [diff] [blame] | 2711 | err_reg: |
| 2712 | pci_release_region(pdev, reg); |
Jiri Slaby | 42f6384 | 2006-12-08 02:39:03 -0800 | [diff] [blame] | 2713 | err_flag: |
| 2714 | board->flags &= ~SX_BOARD_PRESENT; |
Jiri Slaby | 5572e10 | 2006-12-08 02:38:58 -0800 | [diff] [blame] | 2715 | err: |
| 2716 | return retval; |
Jiri Slaby | 3468a33 | 2006-12-13 00:34:20 -0800 | [diff] [blame] | 2717 | #else |
| 2718 | return -ENODEV; |
| 2719 | #endif |
Jiri Slaby | 5572e10 | 2006-12-08 02:38:58 -0800 | [diff] [blame] | 2720 | } |
| 2721 | |
| 2722 | static void __devexit sx_pci_remove(struct pci_dev *pdev) |
| 2723 | { |
| 2724 | struct sx_board *board = pci_get_drvdata(pdev); |
| 2725 | |
Jiri Slaby | 3910349 | 2006-12-08 02:39:07 -0800 | [diff] [blame] | 2726 | sx_remove_card(board, pdev); |
Jiri Slaby | 5572e10 | 2006-12-08 02:38:58 -0800 | [diff] [blame] | 2727 | } |
| 2728 | |
| 2729 | /* Specialix has a whole bunch of cards with 0x2000 as the device ID. They say |
| 2730 | its because the standard requires it. So check for SUBVENDOR_ID. */ |
| 2731 | static struct pci_device_id sx_pci_tbl[] = { |
| 2732 | { PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8, |
Jiri Slaby | c14d444 | 2007-07-10 17:22:25 -0700 | [diff] [blame] | 2733 | .subvendor = PCI_ANY_ID, .subdevice = 0x0200 }, |
Jiri Slaby | 5572e10 | 2006-12-08 02:38:58 -0800 | [diff] [blame] | 2734 | { PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8, |
Jiri Slaby | c14d444 | 2007-07-10 17:22:25 -0700 | [diff] [blame] | 2735 | .subvendor = PCI_ANY_ID, .subdevice = 0x0300 }, |
Jiri Slaby | 5572e10 | 2006-12-08 02:38:58 -0800 | [diff] [blame] | 2736 | { 0 } |
| 2737 | }; |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2738 | |
Jiri Slaby | 5572e10 | 2006-12-08 02:38:58 -0800 | [diff] [blame] | 2739 | MODULE_DEVICE_TABLE(pci, sx_pci_tbl); |
| 2740 | |
| 2741 | static struct pci_driver sx_pcidriver = { |
| 2742 | .name = "sx", |
| 2743 | .id_table = sx_pci_tbl, |
| 2744 | .probe = sx_pci_probe, |
| 2745 | .remove = __devexit_p(sx_pci_remove) |
| 2746 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2747 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2748 | static int __init sx_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2749 | { |
Jiri Slaby | 18f813e | 2006-12-08 02:39:01 -0800 | [diff] [blame] | 2750 | #ifdef CONFIG_EISA |
| 2751 | int retval1; |
| 2752 | #endif |
Jiri Slaby | 927a6f9 | 2006-12-08 02:39:02 -0800 | [diff] [blame] | 2753 | #ifdef CONFIG_ISA |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2754 | struct sx_board *board; |
Jiri Slaby | 927a6f9 | 2006-12-08 02:39:02 -0800 | [diff] [blame] | 2755 | unsigned int i; |
| 2756 | #endif |
| 2757 | unsigned int found = 0; |
| 2758 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2759 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2760 | func_enter(); |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2761 | sx_dprintk(SX_DEBUG_INIT, "Initing sx module... (sx_debug=%d)\n", |
| 2762 | sx_debug); |
| 2763 | if (abs((long)(&sx_debug) - sx_debug) < 0x10000) { |
| 2764 | printk(KERN_WARNING "sx: sx_debug is an address, instead of a " |
| 2765 | "value. Assuming -1.\n(%p)\n", &sx_debug); |
| 2766 | sx_debug = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2767 | } |
| 2768 | |
| 2769 | if (misc_register(&sx_fw_device) < 0) { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2770 | printk(KERN_ERR "SX: Unable to register firmware loader " |
| 2771 | "driver.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2772 | return -EIO; |
| 2773 | } |
Jiri Slaby | 927a6f9 | 2006-12-08 02:39:02 -0800 | [diff] [blame] | 2774 | #ifdef CONFIG_ISA |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2775 | for (i = 0; i < NR_SX_ADDRS; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2776 | board = &boards[found]; |
| 2777 | board->hw_base = sx_probe_addrs[i]; |
Jiri Slaby | 30f4218 | 2006-12-08 02:39:08 -0800 | [diff] [blame] | 2778 | board->hw_len = SX_WINDOW_LEN; |
| 2779 | if (!request_region(board->hw_base, board->hw_len, "sx")) |
| 2780 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2781 | board->base2 = |
Alan Cox | 24cb233 | 2008-04-30 00:54:19 -0700 | [diff] [blame] | 2782 | board->base = ioremap_nocache(board->hw_base, board->hw_len); |
Jiri Slaby | 30f4218 | 2006-12-08 02:39:08 -0800 | [diff] [blame] | 2783 | if (!board->base) |
| 2784 | goto err_sx_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2785 | board->flags &= ~SX_BOARD_TYPE; |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2786 | board->flags |= SX_ISA_BOARD; |
| 2787 | board->irq = sx_irqmask ? -1 : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2788 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2789 | if (probe_sx(board)) { |
Jiri Slaby | 42f6384 | 2006-12-08 02:39:03 -0800 | [diff] [blame] | 2790 | board->flags |= SX_BOARD_PRESENT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2791 | found++; |
| 2792 | } else { |
| 2793 | iounmap(board->base); |
Jiri Slaby | 30f4218 | 2006-12-08 02:39:08 -0800 | [diff] [blame] | 2794 | err_sx_reg: |
| 2795 | release_region(board->hw_base, board->hw_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2796 | } |
| 2797 | } |
| 2798 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2799 | for (i = 0; i < NR_SI_ADDRS; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2800 | board = &boards[found]; |
| 2801 | board->hw_base = si_probe_addrs[i]; |
Jiri Slaby | 30f4218 | 2006-12-08 02:39:08 -0800 | [diff] [blame] | 2802 | board->hw_len = SI2_ISA_WINDOW_LEN; |
| 2803 | if (!request_region(board->hw_base, board->hw_len, "sx")) |
| 2804 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2805 | board->base2 = |
Alan Cox | 24cb233 | 2008-04-30 00:54:19 -0700 | [diff] [blame] | 2806 | board->base = ioremap_nocache(board->hw_base, board->hw_len); |
Jiri Slaby | 30f4218 | 2006-12-08 02:39:08 -0800 | [diff] [blame] | 2807 | if (!board->base) |
| 2808 | goto err_si_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2809 | board->flags &= ~SX_BOARD_TYPE; |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2810 | board->flags |= SI_ISA_BOARD; |
| 2811 | board->irq = sx_irqmask ? -1 : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2812 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2813 | if (probe_si(board)) { |
Jiri Slaby | 42f6384 | 2006-12-08 02:39:03 -0800 | [diff] [blame] | 2814 | board->flags |= SX_BOARD_PRESENT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2815 | found++; |
| 2816 | } else { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2817 | iounmap(board->base); |
Jiri Slaby | 30f4218 | 2006-12-08 02:39:08 -0800 | [diff] [blame] | 2818 | err_si_reg: |
| 2819 | release_region(board->hw_base, board->hw_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2820 | } |
| 2821 | } |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2822 | for (i = 0; i < NR_SI1_ADDRS; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2823 | board = &boards[found]; |
| 2824 | board->hw_base = si1_probe_addrs[i]; |
Jiri Slaby | 30f4218 | 2006-12-08 02:39:08 -0800 | [diff] [blame] | 2825 | board->hw_len = SI1_ISA_WINDOW_LEN; |
| 2826 | if (!request_region(board->hw_base, board->hw_len, "sx")) |
| 2827 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2828 | board->base2 = |
Alan Cox | 24cb233 | 2008-04-30 00:54:19 -0700 | [diff] [blame] | 2829 | board->base = ioremap_nocache(board->hw_base, board->hw_len); |
Jiri Slaby | 30f4218 | 2006-12-08 02:39:08 -0800 | [diff] [blame] | 2830 | if (!board->base) |
| 2831 | goto err_si1_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2832 | board->flags &= ~SX_BOARD_TYPE; |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2833 | board->flags |= SI1_ISA_BOARD; |
| 2834 | board->irq = sx_irqmask ? -1 : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2835 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2836 | if (probe_si(board)) { |
Jiri Slaby | 42f6384 | 2006-12-08 02:39:03 -0800 | [diff] [blame] | 2837 | board->flags |= SX_BOARD_PRESENT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2838 | found++; |
| 2839 | } else { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2840 | iounmap(board->base); |
Jiri Slaby | 30f4218 | 2006-12-08 02:39:08 -0800 | [diff] [blame] | 2841 | err_si1_reg: |
| 2842 | release_region(board->hw_base, board->hw_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2843 | } |
| 2844 | } |
Jiri Slaby | 927a6f9 | 2006-12-08 02:39:02 -0800 | [diff] [blame] | 2845 | #endif |
Jiri Slaby | 18f813e | 2006-12-08 02:39:01 -0800 | [diff] [blame] | 2846 | #ifdef CONFIG_EISA |
| 2847 | retval1 = eisa_driver_register(&sx_eisadriver); |
| 2848 | #endif |
Jiri Slaby | 5572e10 | 2006-12-08 02:38:58 -0800 | [diff] [blame] | 2849 | retval = pci_register_driver(&sx_pcidriver); |
| 2850 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2851 | if (found) { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2852 | printk(KERN_INFO "sx: total of %d boards detected.\n", found); |
Jiri Slaby | 5572e10 | 2006-12-08 02:38:58 -0800 | [diff] [blame] | 2853 | retval = 0; |
| 2854 | } else if (retval) { |
Jiri Slaby | 18f813e | 2006-12-08 02:39:01 -0800 | [diff] [blame] | 2855 | #ifdef CONFIG_EISA |
Jiri Slaby | 7eb9976 | 2006-12-08 02:39:06 -0800 | [diff] [blame] | 2856 | retval = retval1; |
Jiri Slaby | 18f813e | 2006-12-08 02:39:01 -0800 | [diff] [blame] | 2857 | if (retval1) |
| 2858 | #endif |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2859 | misc_deregister(&sx_fw_device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2860 | } |
| 2861 | |
| 2862 | func_exit(); |
Jiri Slaby | 5572e10 | 2006-12-08 02:38:58 -0800 | [diff] [blame] | 2863 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2864 | } |
| 2865 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2866 | static void __exit sx_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2867 | { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2868 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2869 | |
| 2870 | func_enter(); |
Jiri Slaby | 18f813e | 2006-12-08 02:39:01 -0800 | [diff] [blame] | 2871 | #ifdef CONFIG_EISA |
| 2872 | eisa_driver_unregister(&sx_eisadriver); |
| 2873 | #endif |
Jiri Slaby | 5572e10 | 2006-12-08 02:38:58 -0800 | [diff] [blame] | 2874 | pci_unregister_driver(&sx_pcidriver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2875 | |
Jiri Slaby | 55e7071 | 2006-12-08 02:39:03 -0800 | [diff] [blame] | 2876 | for (i = 0; i < SX_NBOARDS; i++) |
Jiri Slaby | 3910349 | 2006-12-08 02:39:07 -0800 | [diff] [blame] | 2877 | sx_remove_card(&boards[i], NULL); |
Jiri Slaby | 55e7071 | 2006-12-08 02:39:03 -0800 | [diff] [blame] | 2878 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2879 | if (misc_deregister(&sx_fw_device) < 0) { |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2880 | printk(KERN_INFO "sx: couldn't deregister firmware loader " |
| 2881 | "device\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2882 | } |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2883 | sx_dprintk(SX_DEBUG_CLEANUP, "Cleaning up drivers (%d)\n", |
| 2884 | sx_initialized); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2885 | if (sx_initialized) |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2886 | sx_release_drivers(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2887 | |
Jiri Slaby | 15b611f | 2006-12-08 02:39:04 -0800 | [diff] [blame] | 2888 | kfree(sx_ports); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2889 | func_exit(); |
| 2890 | } |
| 2891 | |
| 2892 | module_init(sx_init); |
| 2893 | module_exit(sx_exit); |