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