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