cleanup
[linux-2.4.21-pre4.git] / drivers / pcmcia / pccf_4xx.c
1 /* Device driver for the IBM 4xx PCMCIA/CF+ Interface Macro (PCCF)
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Copyright (C) 2001, International Business Machines Corporation
18  * All Rights Reserved.
19  * Copyright (C) 2002 MontaVista Software, Inc. <source@mvista.com>
20  *
21  *  Eric Van Hensbegren <bergevan@us.ibm.com>
22  *  IBM Austin Research Lab
23  *
24  *  Based on original code by Magnus Damm for mpc8xx series driver
25  *
26  *  May, 2001     - Original version for Pecan 
27  *  August, 2001  - Modified by Benjamin Li (IBM Austin) for 405LP
28  *  October, 2001 - Modified/Documented by Bishop Brock (IBM Research Austin)
29  *                  bcbrock@us.ibm.com
30  *  August, 2002  - Conversion to standalone in-kernel driver by Todd
31  *                  Poynor (MontaVista Software)
32  ****************************************************************************
33
34  Module Parameters
35  =================
36
37  pwr5by3=[0|1]
38
39    0 - [ Default ] Cards are powered by the Vcc voltage they require, either
40        3.3 V or 5 V.  If the power rail requested is not available, the card
41        insertion will fail.
42
43    1 - Cards that request 5 V will be powered by 3.3 V instead.  See below for
44        further details.
45
46  ignore_wrprot=[0|1]
47
48    0 - [ Default ] Drivers that request write-protected regions will fail
49        unless the configuration can actually write protect the region.  
50
51    1 - If this module can satisfy a request to write protect a region it will,
52        otherwise it will simply print a warning and carry on.
53
54   pc_debug=<n>
55
56    A standard parameter for PCMCIA modules.  If modules are compiled with
57    -DPCMCIA_DEBUG=<m>, then debugging prints are enabled and <m> is the default
58    debugging level.  The level can be changed by the pc_debug=<n> parameter
59    when the module is loaded. Debug level 0 suppresses all messages.
60
61  Introduction
62  ============
63
64  The 4xx PCCF (PCMCIA/CF+) macro is an "internal" EBC peripheral that sits
65  between the EBC controller and the chip IOs.  When enabled, PCCF takes control
66  of 4 EBC chip selects and other EBC signals, and does a straightforward
67  mapping of EBC transactions to PCMCIA/CF+ transactions. The type of PCMCIA/CF+
68  transaction (Attribute Memory, Common Memory, I/O, or Macro Control) is
69  determined by a simple address decode of the high-order bits of the physical
70  address.  PCCF was first implemented as an external EBC peripheral in an FPGA
71  on the IBM Austin Research Pecan board.
72
73  PCCF is not compatible with the ExCA standard.  PCCF supports only a single
74  memory window, and this driver does not attempt to partition the single
75  physical window into multiple virtual windows.  Although the PCCF macro
76  supports only a single IO area as well, this driver gives the illusion that 2
77  IO windows exist.  This is possible because IO windows don't involve address
78  translation. On the other hand, the implementation can not support different
79  IO window-specific parameters on the two IO windows.
80
81  As implemented in the 405LP, PCCF is not strictly compatible with the PCMCIA
82  specification, as it only provides 23 of the 26 address bits called for in the
83  specification.  Thus 405LP/PCCF may not support some archaic PCMCIA SRAM
84  cards, but will support modern PCMCIA cards such as IDE disks and network
85  adapters, and fully support CF+ cards (but see discussion on power below).
86
87  PCCF supports a single PCMCIA/CF slot.
88
89  EBC Setup and Memory Map
90  =========================
91
92  The EBC interface to PCCF can be configured in numerous ways.  Also, the
93  ability of PCCF to generate valid PCMCIA/CF transactions critically depends on
94  the proper setup of the access parameters (EBC0_BnAP) register(s) for the EBC
95  bank(s) controlling PCCF.  EBC setup is currently handled by this driver for
96  all supported configurations.  This driver maps the PCCF macro in a single EBC
97  bank at a configuration-dependent address, and the access parameters provide a
98  minimum 300 ns cycle time for all memory and IO accesses.  The EBC access
99  parameters *must* include sample-on-ready to allow slow devices to control the
100  timing of their transactions, and the EBC0_CFG register will specify at least
101  a 12 us timeout (for PCMCIA specification compatibility).
102  In order to guarantee correct operation for all cards, the board
103  design must correctly bring in the PCMCIA WAIT# signal.
104
105  The PCCF macro maps a 32 MB physical address space as indicated below.
106  Offsets are relative to the physical base address.
107
108  0x00000000 - 0x007fffff : 8 MB PCCF control register space
109  0x00800000 - 0x00ffffff : 8 MB Attribute memory space
110  0x01000000 - 0x017fffff : 8 MB Common memory space
111  0x01800000 - 0x018fffff : 8 MB I/O space
112
113  Endianess
114  =========
115
116  PCMCIA is a little-endian specification.  The PCCF controller byte-swaps all
117  16-bit accesses.  This means that 16-bit accesses will need to use
118  byte-swapping IO, as normally occurs in 4xx kernels.  The PCCF control
119  registers are big-endian, however.  That's why the accesses of those registers
120  use in_be16 and out_be16, which are non-swapping operations.
121
122  A note on IDE: IDE control and status operations are 8-bit operations, so
123  endianess is not an issue.  IDE sector reads/writes do not use swapping IO on
124  PowerPC, *except* for the IDE identification sector, which is swapped so that
125  it can be interpreted.  This allows removable drives to be created on e.g., an
126  IA32 laptop and read with this controller and vice versa.
127
128  Legacy IO and Address Mapping
129  =============================
130
131  Requests for memory windows are given a physical address, which the caller
132  will (redundantly) ioremap().  Requests for I/O space windows are not
133  modified.  For legacy IO to work, the _IO_BASE symbols is set to reference
134  isa_io_base, which holds the virtual address of our IO area mapping.
135
136  Power Considerations
137  ====================
138
139  Vcc
140  ---
141
142  The PCCF macro control register includes bits for both 3.3 V and 5 V, Vcc
143  control. On the 405LP, however, only the 3.3 V control is brought out of the
144  chip, as 405LP I/O are not 5 V compliant. 
145
146  To reduce I/O count the 405LP also does not connect the VS2# signal.  VS2# is
147  pulled high internally to the PCCF macro.
148
149  A 405LP-based system designed for 5 V PCMCIA support will require external
150  voltage-conversion buffers and an alternate means for selecting the 5 V Vcc
151  level, e.g., a GPIO pin or CPLD (as on Beech) . Similarly, a 405LP-based
152  system providing X.X V operation will need a way to signal VS2#.
153
154  The Pecan FPGA implementation of PCCF supports both 3.3 V and 5 V operation,
155  and both VS1# and VS2#.
156
157  If the current configuration does not support 5V operation, then inserting a 5
158  V card into the slot will fail. Vcc = 3.3 V is always assumed to be present.
159  Some "5 V" PCMCIA cards will operate correctly at Vcc = 3.3 V, however.  To
160  support this mode of operation, the driver can be loaded with the parameter
161
162  pwr5by3=1
163
164  which will cause all 5 V cards to be powered by 3.3 V (even if the
165  configuration normally supports 5 V operation).  Beware that this may cause
166  equipment damage (unlikely on a well-designed board) or loss of data (perhaps
167  more likely).
168
169  Vpp
170  ---
171
172  PCCF does not directly support Vpp power selection.  The default assumption is
173  that the external power supply is configured according to the PCMCIA standard,
174  and will supply Vpp = Vcc when power is applied to the socket.  If a board is
175  constructed such that Vpp power selection is possible, the routine
176  set_Vpp() et. al. will need to be changed accordingly.
177
178  Limitations
179  ===========
180
181  The controller does not generate interrupts for memory-card status change
182  events such as battery voltage changes or changes on the READY/BUSY line.
183
184  The macro and card IRQ lines are fixed; The controller can not route the card
185  interrupt to another IRQ.  This may have implications for legacy device
186  drivers.
187
188  The PCCF macro includes a single control register for all of the memory and IO
189  registers.  It is not possible to set different access parameters (i.e.,
190  8-bit, 16-bit, auto-size) for different areas.  The access parameters are
191  reset every time a new memory or I/O window is mapped.  This may cause some
192  device drivers to fail when using this controller.
193
194  Furthermore, this module assumes that the highest-level device driver knows
195  whether it is accessing 8- or 16-bit IO registers, and it is up to the driver
196  to do inb(), inw() etc. as appropriate for the IO area being accessed.  The
197  PCCF macro can not split 16-bit bus transactions into a pair of 8-bit
198  transactions as some other controllers can.
199
200  There is currently no support for optimizing memory and IO access speeds.  [
201  It's not clear this is ever used; In any event, don't do this until we have
202  our variable-speed mechanism in place. ]
203
204  There is currently no support for write-protecting windows.  This can be added
205  but will require BIOS-like intervention to reprogram the EBC banks as
206  protection comes on and off line.  Single EBC-bank configurations like Pecan
207  will be difficult and painful to write-protect correctly.
208
209 ****************************************************************************/
210
211 #include <linux/module.h>
212 #include <linux/init.h>
213 #include <linux/types.h>
214 #include <linux/fcntl.h>
215 #include <linux/string.h>
216
217 #include <asm/io.h>
218 #include <asm/bitops.h>
219 #include <asm/segment.h>
220 #include <asm/system.h>
221 #include <asm/irq.h>
222
223 #include <linux/kernel.h>
224 #include <linux/errno.h>
225 #include <linux/sched.h>
226 #include <linux/slab.h>
227 #include <linux/timer.h>
228 #include <linux/ioport.h>
229 #include <linux/delay.h>
230 #include <linux/kmod.h>
231
232 #include <pcmcia/version.h>
233 #include <pcmcia/cs_types.h>
234 #include <pcmcia/cs.h>
235 #include <pcmcia/ss.h>
236 #include <pcmcia/bus_ops.h>
237
238 #include <asm/byteorder.h>
239 #include <asm/pccf_4xx.h>
240
241 MODULE_AUTHOR("Eric Van Hensbergen <bergevan@us.ibm.com>");
242 MODULE_DESCRIPTION("IBM PCCF 4xx socket driver");
243 MODULE_PARM(pwr5by3, "i");
244 MODULE_PARM_DESC(pwr5by3, "Experimental: Power 5 V cards with 3.3 V");
245 MODULE_PARM(ignore_wrprot, "i");
246 MODULE_PARM_DESC(ignore_wrprot, "Experimental: Ignore write protect requests");
247
248 static int pwr5by3 = 0;
249 static int ignore_wrprot = 0;
250
251 static const char *version =
252     "pccf_4xx.c $Revision: 1.1.1.1 $ $Date: 2005/04/11 02:50:33 $ (Eric Van Hensbergen)";
253
254 #define PCMCIA_DEBUG 0
255
256 #ifdef PCMCIA_DEBUG
257 static int pc_debug = PCMCIA_DEBUG;
258 MODULE_PARM(pc_debug, "i");
259 MODULE_PARM_DESC(pc_debug,
260                  "Set pc_debug to a non-0 value to enable debug msgs.");
261 #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
262 #else
263 #define DEBUG(n, args...)
264 #endif
265
266 /* Configurations */
267
268 #define VCC5V_SUPPORT 1
269
270 /* Minimum bus cycle time (in ns) */
271
272 #define MIN_SPEED 300
273
274 #define PCMCIA_ATTRIB_OFFSET    0x00800000
275 #define PCMCIA_ATTRIB_PADDR     (PCCF_4XX_PADDR + PCMCIA_ATTRIB_OFFSET)
276
277 #define PCMCIA_MEM_WIN_NO               1
278 #define PCMCIA_IO_WIN_NO                2
279
280 #define PCMCIA_CTRL(offset)\
281  ((volatile unsigned short *)((u8 *) pccf_4xx_macro_vaddr + (offset)))
282
283 /* PCCF control registers are big-endian */
284
285 #define GET_PCMCIA_CTRL(offset)        (in_be16(PCMCIA_CTRL(offset)))
286 #define SET_PCMCIA_CTRL(value, offset) (out_be16(PCMCIA_CTRL(offset), value))
287
288 #define PCMCIA_CSR GET_PCMCIA_CTRL(0x00)        /* Card Status Register */
289 #define PCMCIA_CCR GET_PCMCIA_CTRL(0x02)        /* Card Control Register */
290 #define PCMCIA_ISR GET_PCMCIA_CTRL(0x04)        /* Interrupt Status Register */
291 #define PCMCIA_ICR GET_PCMCIA_CTRL(0x06)        /* Interrupt Control Register */
292 #define PCMCIA_MRR GET_PCMCIA_CTRL(0x0e)        /* Macro Reset Register */
293
294 #define SET_PCMCIA_CSR(value)           SET_PCMCIA_CTRL(value, 0x00)
295 #define SET_PCMCIA_CCR(value)           SET_PCMCIA_CTRL(value, 0x02)
296 #define SET_PCMCIA_ISR(value)           SET_PCMCIA_CTRL(value, 0x04)
297 #define SET_PCMCIA_ICR(value)           SET_PCMCIA_CTRL(value, 0x06)
298 #define SET_PCMCIA_MRR(value)           SET_PCMCIA_CTRL(value, 0x0e)
299
300 #ifndef get_field16
301 #define get_field16(reg, hi, lo)\
302 ((reg >> (15 - (lo))) & ~(-1 << ((lo) - (hi) + 1)))
303
304 #define make_field16(val, hi, lo)\
305 (((val) & ~(-1 << ((lo) - (hi) + 1))) << (15 - (lo)))
306 #endif                          /* get_field16 */
307
308 #ifndef get_field32
309 #define get_field32(reg, hi, lo)\
310 ((reg >> (31 - (lo))) & ~(-1 << ((lo) - (hi) + 1)))
311
312 #define make_field32(val, hi, lo)\
313 (((val) & ~(-1 << ((lo) - (hi) + 1))) << (31 - (lo)))
314
315 #define set_field32(word, hi, lo, val)\
316 (((word) & ~(make_field32(0xffffffff, hi, lo))) | make_field32(val, hi, lo))
317 #endif                          /* get_field32 */
318
319 #define PCMCIA_CSR_DETECT(csr)          (get_field16(csr, 2, 2))
320 #define PCMCIA_CSR_VS1(csr)             (get_field16(csr, 5, 5))
321 #define PCMCIA_CSR_VS2(csr)             (get_field16(csr, 4, 4))
322 #define PCMCIA_CSR_IO(csr)              (get_field16(csr, 8, 8))
323 #define PCMCIA_CSR_PWR(csr)             (get_field16(csr, 14, 15))
324 #define PCMCIA_CSR_READY(csr)           (get_field16(csr, 12, 12)==0)
325
326 #define PCMCIA_CCR_MODE(ccr)            get_field16(ccr, 0, 1)
327 #define PCMCIA_CCR_3V(ccr)              get_field16(ccr, 6, 6)
328 #define PCMCIA_CCR_5V(ccr)              get_field16(ccr, 7, 7)
329 #define PCMCIA_CCR_816(ccr)             get_field16(ccr, 12, 12)
330 #define PCMCIA_CCR_IOIS16(ccr)          get_field16(ccr, 13, 13)
331
332 #define PCMCIA_ISR_STSCHG(isr)          get_field16(isr, 6, 6)
333 #define PCMCIA_ISR_DETECT(isr)          get_field16(isr, 7, 7)
334
335 #define PCMCIA_ICR_STSCHG(icr)          get_field16(icr, 4, 4)
336 #define PCMCIA_ICR_DETECT(icr)          get_field16(icr, 5, 5)
337
338 /*  These are values used to represent voltage levels  */
339 #define VOLT00                          00
340 #define VOLT33                          33
341 #define VOLT50                          50
342 \f
343 /****************************************************************************
344   PCCF control routines
345 ****************************************************************************/
346
347 /* Pecan and Beech Pass 1 use the PCCF macro for power control (although Beech
348    Pass 1 doesn't support +5V.
349
350    Beech Pass 2 uses an FPGA register to control the 5V power supply.  When
351    moving between power modes on Beech, we're always careful to transit via a
352    state that carefully powers-down the socket (order is important).  The
353    ground state on the Beech 2 socket power is PCCF 3V bit == 0, FPGA 5V bit =
354    0.  Setting exactly one of these to 1 enables the proper voltage on the
355    socket. */
356
357 static void
358 pcmcia_0v(void)
359 {                               /* Remove power */
360
361 #if defined(CONFIG_BEECH)
362         {
363                 unsigned long flags;
364
365                 save_flags(flags);
366                 cli();
367                 *beech_fpga_reg_4 &= ~FPGA_REG_4_PCMCIA_5V;
368                 restore_flags(flags);
369         }
370 #endif
371
372         {
373                 unsigned short ccr = PCMCIA_CCR;
374
375                 ccr &= ~0x0200; /* -+3V */
376                 ccr &= ~0x0100; /* -+5V */
377                 SET_PCMCIA_CCR(ccr);
378         }
379 }
380
381 static void
382 pcmcia_3v(void)
383 {                               /* Supply 3 V */
384         unsigned short ccr = PCMCIA_CCR;
385
386         pcmcia_0v();
387
388         ccr |= 0x0200;          /* ++3V */
389         ccr &= ~0x0100;         /* -+5V */
390         SET_PCMCIA_CCR(ccr);
391 }
392
393 static void
394 pcmcia_5v(void)
395 {                               /* Supply 5 V */
396         unsigned short ccr = PCMCIA_CCR;
397
398         pcmcia_0v();
399
400         ccr &= ~0x0200;         /* -+3V */
401         ccr |= 0x0100;          /* ++5V */
402         SET_PCMCIA_CCR(ccr);
403
404 #if defined(CONFIG_BEECH)
405         {
406                 unsigned long flags;
407
408                 save_flags(flags);
409                 cli();
410                 *beech_fpga_reg_4 |= FPGA_REG_4_PCMCIA_5V;
411                 restore_flags(flags);
412         }
413 #endif
414 }
415
416 static void
417 pcmcia_reset(void)
418 {                               /* Assert card reset for 10 us */
419         unsigned short ccr = PCMCIA_CCR;
420
421         ccr |= 0x0080;          /* Reset */
422         SET_PCMCIA_CCR(ccr);
423         udelay(10);
424         ccr = PCMCIA_CCR;
425         ccr &= ~0x0080;
426         SET_PCMCIA_CCR(ccr);
427 }
428
429 static void
430 pcmcia_mrr(void)
431 {                               /* Reset the PCCF macro */
432         SET_PCMCIA_MRR(0xffff);
433 }
434
435 static void
436 pcmcia_mem(void)
437 {                               /* Set memory mode */
438         unsigned short ccr = PCMCIA_CCR;
439
440         ccr |= 0xc000;
441         SET_PCMCIA_CCR(ccr);
442 }
443
444 static void
445 pcmcia_io(void)
446 {                               /* Set memory and IO mode */
447         unsigned short ccr = PCMCIA_CCR;
448
449         ccr |= 0x4000;
450         ccr &= ~0x8000;
451         SET_PCMCIA_CCR(ccr);
452 }
453
454 static void
455 pcmcia_clr_cdi(void)
456 {                               /* Clear the card-detect interrupt */
457         unsigned short icr = PCMCIA_ICR;
458
459         icr |= 0x0100;
460         SET_PCMCIA_ICR(icr);
461         icr = PCMCIA_ICR;
462         icr &= ~0x0100;
463         SET_PCMCIA_ICR(icr);
464 }
465
466 static void
467 pcmcia_unmask_cdi(void)
468 {                               /* Unmask the card-detect interrupt */
469         unsigned short icr = PCMCIA_ICR;
470
471         icr &= ~0x0400;
472         SET_PCMCIA_ICR(icr);
473 }
474
475 static void
476 pcmcia_unmask_sti(void)
477 {                               /* Unmask the status-change interrupt */
478         unsigned short icr = PCMCIA_ICR;
479
480         icr &= ~0x0800;
481         SET_PCMCIA_ICR(icr);
482 }
483
484 static void
485 pcmcia_mask_cdi(void)
486 {                               /* Mask the card-detect interrupt */
487         unsigned short icr = PCMCIA_ICR;
488
489         icr |= 0x0400;
490         SET_PCMCIA_ICR(icr);
491 }
492
493 static void
494 pcmcia_mask_sti(void)
495 {                               /* Mask the status-change interrupt */
496         unsigned short icr = PCMCIA_ICR;
497
498         icr |= 0x0800;
499         SET_PCMCIA_ICR(icr);
500 }
501
502 static void
503 pcmcia_16bit(void)
504 {                               /* Set 16-bit mode */
505         unsigned short ccr = PCMCIA_CCR;
506
507         ccr &= ~0x000c;
508         SET_PCMCIA_CCR(ccr);
509 }
510
511 static void
512 pcmcia_autosz(void)
513 {                               /* Set IOIS16# mode */
514         unsigned short ccr = PCMCIA_CCR;
515
516         ccr &= ~0x000c;
517         ccr |= 0x0004;
518         SET_PCMCIA_CCR(ccr);
519 }
520
521 static void
522 pcmcia_8bit(void)
523 {                               /* Set 8-bit mode */
524         unsigned short ccr = PCMCIA_CCR;
525
526         ccr &= ~0x000c;
527         ccr |= 0x0008;
528         SET_PCMCIA_CCR(ccr);
529 }
530 \f
531 /* This structure records the macro interrupt number and its handler and
532    private data, a saved copy of the socket state, and memory and IO window
533    structures. */
534
535 typedef struct socket_info_t {
536         u_char intr;
537         void (*handler) (void *info, u_int events);
538         void *info;
539         socket_state_t state;
540         struct pccard_mem_map mem_win[PCMCIA_MEM_WIN_NO];
541         struct pccard_io_map io_win[PCMCIA_IO_WIN_NO];
542 } socket_info_t;
543
544 /* Our socket(s) support(s) PCMCIA/CF+ cards (not cardbus) with static memory
545    maps, no ISA IRQs, and a single fixed socket interrupt. 
546
547    The PCCF controller does not place any restrictions on memory window sizes.
548    However, the card services driver seems to use the map_size a lot during
549    numerous ioremap()ing and iounmap()ing operations.  To be safe we are
550    setting the map_size parameter to PAGE_SIZE, which is (similar to) what
551    other drivers do.
552
553 */
554
555 static socket_cap_t capabilities = {
556         SS_CAP_PCCARD | SS_CAP_STATIC_MAP,      /* PCMCIA, static map */
557         0,                      /* No ISA interrupts */
558         PAGE_SIZE,              /* Window size granularity */
559         0,                      /* io_offset */
560         PCCF_4XX_CARD_IRQ,              /* Single fixed socket interrupt */
561         NULL,                   /* No CardBus support */
562         NULL                    /* No virtual bus operations */
563 };
564
565 /* Socket parameters and data */
566
567 #define TOTAL_NUM_OF_SOCKETS            1
568 static int sockets = TOTAL_NUM_OF_SOCKETS;
569 static socket_info_t socket[TOTAL_NUM_OF_SOCKETS];
570 \f
571 /****************************************************************************
572   Configuration-specific code
573 ****************************************************************************/
574
575 /* Voltage control.  See comments at the beginning of the file.
576
577    The 'poweroff' situation is called out separately because we also use the
578    occasion of a powerdown to reset some state.  This is the default state of
579    the socket - status change interrupt masked, the card in memory mode and
580    16-bit mode.
581
582    These routines will probably be slightly different for each
583    chip/board. set_voltage() is called with the requested Vcc and Vpp values,
584    which may be modified. In the event of an error, power is removed from the
585    socket. */
586
587 static int
588 set_Vcc(int *Vcc)
589 {
590         switch (*Vcc) {
591         case VOLT00:
592         case VOLT33:
593                 break;
594         case VOLT50:
595                 if (pwr5by3) {
596                         printk(KERN_WARNING "pccf_4xx: Warning: Powering 5 V "
597                                "card with 3.3 V.  Good Luck!\n");
598                         *Vcc = VOLT33;
599                 } else if (!VCC5V_SUPPORT) {
600                         printk(KERN_ERR "pccf_4xx: The card requested "
601                                "Vcc = 5 V, which is not supported by this\n"
602                                "platform.  You can try reloading the module "
603                                " with the parameter pwr5by3=1,\n"
604                                "which will cause all 5 V cards to be powered "
605                                " by 3.3 V.  Beware that this may cause\n"
606                                "equipment damage or loss of data.\n");
607                         return -EINVAL;
608                 }
609                 break;
610         default:
611                 printk(KERN_ERR "pccf_4xx: Illegal Vcc voltage = %d\n", *Vcc);
612                 return -EINVAL;
613                 break;
614         }
615
616         switch (*Vcc) {
617         case VOLT00:
618                 pcmcia_0v();
619                 break;
620         case VOLT33:
621                 pcmcia_3v();
622                 break;
623         default:
624                 pcmcia_5v();
625                 break;
626         }
627         return 0;
628 }
629
630 /* We assume that if Vpp request is <= Vcc, then Vcc = Vpp is OK.  If we're in
631    pwr5by3 mode then Vcc 3.3, Vpp = 5 is OK, too. The thing that can't be
632    supported (on PECAN) are old memory cards that require 12 V for flash
633    update.  */
634
635 static int
636 set_Vpp(int *Vcc, int *Vpp)
637 {
638         if (*Vcc != *Vpp) {
639                 if (*Vpp > *Vcc) {
640                         if (!(pwr5by3 && (*Vcc = VOLT33) & (*Vpp = VOLT50))) {
641                                 printk(KERN_ERR "pccf_4xx: Can't supply"
642                                        " Vpp = %d with Vcc = %d\n", *Vpp, *Vcc);
643                                 return -EINVAL;
644                         }
645                 }
646                 DEBUG(0, "pccf_4xx: Setting Vpp = Vcc = "
647                       "%d.%d\n", *Vcc / 10, *Vcc % 10);
648                 *Vpp = *Vcc;
649         }
650         return 0;
651 }
652
653 static void
654 poweroff(void)
655 {
656         int Vcc = 0, Vpp = 0;
657
658         set_Vcc(&Vcc);
659         set_Vpp(&Vcc, &Vpp);
660         pcmcia_mask_sti();
661         pcmcia_mem();
662         pcmcia_16bit();
663 }
664
665 static int
666 set_voltage(int *Vcc, int *Vpp)
667 {
668         if ((*Vcc == 0) && (*Vpp == 0))
669                 poweroff();
670         if (set_Vcc(Vcc))
671                 goto error_exit;
672         if (set_Vpp(Vcc, Vpp))
673                 goto error_exit;
674         return 0;
675
676       error_exit:
677         poweroff();
678         return -EINVAL;
679 }
680
681 /* Write protection is currently unimplemented */
682
683 static int
684 write_protect_io(unsigned int sock, u_char map)
685 {
686         if (ignore_wrprot) {
687                 printk(KERN_WARNING "pccf_4xx: Request to write protect IO "
688                        "map %d on socket %d will be ignored.\n", map, sock);
689                 return 0;
690         } else {
691                 printk(KERN_ERR "pccf_4xx: Request to write protect IO "
692                        "map %d on socket %d can not be satisfied. "
693                        "Aborting.\n You can try reloading the module "
694                        "with the paramater ignore_wrprot=1 which "
695                        "will aviod this error, but might allow "
696                        "critical data on the card to be overwritten.\n",
697                        map, sock);
698                 return -EINVAL;
699         }
700 }
701
702 static int
703 write_unprotect_io(unsigned int sock, u_char map)
704 {
705         return 0;
706 }
707
708 static int
709 write_protect_mem(unsigned int sock, u_char map)
710 {
711         if (ignore_wrprot) {
712                 printk(KERN_WARNING "pccf_4xx: Request to write protect "
713                        "memory map %d on socket %d will be ignored.\n",
714                        map, sock);
715                 return 0;
716         } else {
717                 printk(KERN_ERR "pccf_4xx: Request to write protect memory "
718                        "map %d on socket %d can not be satisfied. "
719                        "Aborting.\n You can try reloading the module "
720                        "with the paramater ignore_wrprot=1 which "
721                        "will aviod this error, but might allow "
722                        "critical data on the card to be overwritten.\n",
723                        map, sock);
724                 return -EINVAL;
725         }
726 }
727
728 static int
729 write_unprotect_mem(unsigned int sock, u_char map)
730 {
731         return 0;
732 }
733 \f
734 /****************************************************************************
735    PCMCIA Driver
736 ****************************************************************************/
737
738 /* This is the handler for the PCCF macro interrupt.  The only interrupts
739    signalled by PCCF are the card detection and status change. This driver can
740    only clear the card-detect interrupt - the card driver must take care of
741    status change interrupts. The status-change interrupt bit is only asserted
742    by PCCF when in IO mode. 
743
744    Card detect interrupts always power off the socket and return the socket to
745    an initial state. If a card-detect interrupt occurs any status change
746    interrupt is bogus and is ignored -- the card ain*t there or has just been
747    inserted. */
748
749 static u_int pending_events[TOTAL_NUM_OF_SOCKETS];
750 static spinlock_t pending_event_lock = SPIN_LOCK_UNLOCKED;
751
752 static void
753 pccf_4xx_task(void *dummy)
754 {
755         u_int events;
756         int i;
757
758         for (i = 0; i < TOTAL_NUM_OF_SOCKETS; i++) {
759                 spin_lock_irq(&pending_event_lock);
760                 events = pending_events[i];
761                 pending_events[i] = 0;
762                 spin_unlock_irq(&pending_event_lock);
763
764                 if (events && socket[i].handler)
765                         socket[i].handler(socket[i].info, events);
766         }
767 }
768
769 static struct tq_struct pccf_4xx_tqentry = {
770         routine:pccf_4xx_task
771 };
772
773 static void
774 pccf_4xx_interrupt(int irq, void *dev, struct pt_regs *regs)
775 {
776         unsigned int events;
777         unsigned short isr = PCMCIA_ISR;
778
779         DEBUG(4, "pccf_4xx: interrupt(%d)\n"
780               "csr = 0x%04x, ccr = 0x%04x, isr = 0x%04x icr = 0x%04x\n",
781               irq, PCMCIA_CSR, PCMCIA_CCR, PCMCIA_ISR, PCMCIA_ICR);
782
783         if (PCMCIA_ISR_DETECT(isr)) {
784                 pcmcia_clr_cdi();
785                 poweroff();
786                 events = SS_DETECT;
787         } else if (PCMCIA_ISR_STSCHG(isr))
788                 events = SS_STSCHG;
789         else
790                 events = 0;
791
792         DEBUG(2, "pccf_4xx: socket 0 event 0x%02x\n", events);
793
794         if (events) {
795                 spin_lock(&pending_event_lock);
796                 pending_events[0] |= events;
797                 spin_unlock(&pending_event_lock);
798                 schedule_task(&pccf_4xx_tqentry);
799         }
800 }
801
802 /* This routine registers a callback to be called when the socket driver
803    receives card status change events. */
804
805 static int
806 pccf_4xx_register_callback(unsigned int sock,
807                            void (*handler) (void *, unsigned int), void *info)
808 {
809         DEBUG(4, "pccf_4xx: register_callback(%d) = 0x%p, 0x%p\n",
810               sock, handler, info);
811
812         if (sock >= TOTAL_NUM_OF_SOCKETS)
813                 return -EINVAL;
814
815         socket[sock].handler = handler;
816         socket[sock].info = info;
817         if (handler == NULL) {
818                 MOD_DEC_USE_COUNT;
819         } else {
820                 MOD_INC_USE_COUNT;
821         }
822         return 0;
823 }
824
825 /* The capabilities are copied to the caller. */
826
827 static int
828 pccf_4xx_inquire_socket(unsigned int sock, socket_cap_t * cap)
829 {
830         if (sock >= TOTAL_NUM_OF_SOCKETS) {
831                 DEBUG(4, "pccf_4xx: inquire_socket(%d) failed\n", sock);
832                 return -EINVAL;
833         }
834
835         DEBUG(0, "pccf_4xx: inquire_socket(%d)\n", sock);
836
837         *cap = capabilities;
838         return 0;
839 }
840
841 /* Return the socket status. The PCCF controller does not support all of the
842    status signals, e.g., the BVD signals. The SS_STSCHG flag is only set if an
843    unmasked STSCHG interrupt is pending. */
844
845 static int
846 pccf_4xx_get_status(unsigned int sock, u_int * value)
847 {
848         unsigned short csr = PCMCIA_CSR;
849         unsigned short isr = PCMCIA_ISR;
850         *value = 0;
851
852         if (sock >= TOTAL_NUM_OF_SOCKETS) {
853                 DEBUG(4, "pccf_4xx: get_status(%d) failed\n", sock);
854                 return -EINVAL;
855         }
856
857         if (PCMCIA_CSR_DETECT(csr)) {
858                 *value |= SS_DETECT;
859         }
860         if (PCMCIA_CSR_IO(csr)) {
861                 if (PCMCIA_ISR_STSCHG(isr))
862                         *value |= SS_STSCHG;
863         } else {
864                 if (PCMCIA_CSR_READY(csr)) {
865                         *value |= SS_READY;
866                 }
867         }
868
869         if (PCMCIA_CSR_PWR(csr)) {
870                 *value |= SS_POWERON;
871         }
872
873         switch ((PCMCIA_CSR_VS1(csr) << 1) | PCMCIA_CSR_VS2(csr)) {
874         case 3:         /* 5V card */
875                 break;
876         case 1:
877                 *value |= SS_3VCARD;
878                 break;
879         default:
880                 *value |= SS_XVCARD;
881                 break;
882         };
883
884         DEBUG(1, "pccf_4xx: GetStatus(%d) = %#4.4x\n", sock, *value);
885         return 0;
886 }
887
888 /* Copy the socket state structure. */
889
890 static int
891 pccf_4xx_get_socket(unsigned int sock, socket_state_t * state)
892 {
893         if (sock >= TOTAL_NUM_OF_SOCKETS) {
894                 DEBUG(4, "pccf_4xx: get_socket(%d) failed\n", sock);
895                 return -EINVAL;
896         }
897
898         *state = socket[sock].state;    /* copy the whole structure */
899
900         DEBUG(3, "GetSocket(%d) = flags %#3.3x, Vcc %d, Vpp %d, "
901               "io_irq %d, csc_mask %#2.2x\n", sock, state->flags,
902               state->Vcc, state->Vpp, state->io_irq, state->csc_mask);
903         return 0;
904 }
905
906 /* Set the socket parameters, and apply power to the slot. 
907
908    If the io_irq error is triggered it would indicate that the card driver has
909    its own idea of which interrupt it wants to use, and that its idea is
910    wrong. Again, this controller does not generate interrupts for memory card
911    status changes. */
912
913 static int
914 pccf_4xx_set_socket(unsigned int sock, socket_state_t * state)
915 {
916         int Vcc = state->Vcc;
917         int Vpp = state->Vpp;
918
919         if (sock >= TOTAL_NUM_OF_SOCKETS) {
920                 DEBUG(4, "pccf_4xx: set_socket(%d) failed\n", sock);
921                 return -EINVAL;
922         }
923
924         DEBUG(1, "pccf_4xx: SetSocket(%d, flags %#3.3x, Vcc %d, Vpp %d, "
925               "io_irq %d, csc_mask %#2.2x)\n", sock, state->flags,
926               state->Vcc, state->Vpp, state->io_irq, state->csc_mask);
927
928         /* Apply/remove power */
929
930         set_voltage(&Vcc, &Vpp);
931
932         /* Decode csc_mask requests. */
933
934         if (state->csc_mask & SS_DETECT)
935                 pcmcia_unmask_cdi();
936         else
937                 pcmcia_mask_cdi();      /* This would be extremely bizarre */
938
939         if (state->csc_mask & SS_STSCHG)
940                 pcmcia_unmask_sti();
941         else
942                 pcmcia_mask_sti();
943
944         if (state->csc_mask & (SS_READY | SS_BATDEAD | SS_BATWARN))
945                 printk(KERN_WARNING "pccf_4xx: Warning: The PCMCIA controller "
946                        "is unable to automatically detect one or more memory "
947                        "card status changes requested by the device driver. "
948                        "The installed device may not function correctly with "
949                        "this driver in this system, and data may be lost "
950                        "due to battery failure.\n");
951
952         /* Perform flag actions */
953
954         if (state->flags & SS_RESET) {
955                 if (Vcc == VOLT00)
956                         printk(KERN_WARNING "pccf_4xx: Request to reset "
957                                " unpowered slot ignored\n");
958                 else
959                         pcmcia_reset();
960         }
961
962         if (state->flags & SS_IOCARD) {
963                 pcmcia_io();
964                 if (state->io_irq && (state->io_irq != PCCF_4XX_CARD_IRQ)) {
965                         printk(KERN_CRIT "pccf_4xx: io_irq requested as %d, "
966                                "should be %d. Aborting.\n",
967                                state->io_irq, PCCF_4XX_CARD_IRQ);
968                         return -EINVAL;
969                 }
970         } else {
971                 pcmcia_mem();
972         }
973
974         if (state->flags & SS_SPKR_ENA)
975                 printk(KERN_WARNING "pccf_4xx: The request to enable the "
976                        " speaker pin of the installed card will be "
977                        "ignored.\n");
978
979         /* SS_OUTPUT_ENA -- Nothing to do here in any supported
980            configuration
981            SS_PWR_AUTO   -- Not supported by the controller */
982
983         /* Copy the state to the socket */
984
985         socket[sock].state = *state;
986
987         return 0;
988 }
989
990 /* Copy the IO map back to the caller */
991
992 static int
993 pccf_4xx_get_io_map(unsigned int sock, struct pccard_io_map *io)
994 {
995         u_char map;
996
997         if (sock >= TOTAL_NUM_OF_SOCKETS) {
998                 DEBUG(4, "pccf_4xx: get_io_map(%d) failed\n", sock);
999                 return -EINVAL;
1000         }
1001
1002         map = io->map;
1003         if (io->map >= PCMCIA_IO_WIN_NO) {
1004                 printk(KERN_ERR "pccf_4xx: Driver requested IO map %d "
1005                        "which is not supported by this controller\n", map);
1006                 return -EINVAL;
1007         }
1008
1009         *io = socket[sock].io_win[io->map];
1010
1011         DEBUG(1, "pccf_4xx: GetIOMap(%d, %d) = %#2.2x, %d ns, "
1012               "%#4.4x-%#4.4x\n", sock, map, io->flags, io->speed,
1013               io->start, io->stop);
1014         return 0;
1015 }
1016
1017 /* Set up an IO map. This driver uses 2 virtual windows, although there is only
1018    one physical address space on the PCCF macro.
1019
1020    There's nothing really to "turn on" here.  We presume the EBC is always set
1021    up and ready to go. */
1022
1023 static int
1024 pccf_4xx_set_io_map(unsigned int sock, struct pccard_io_map *io)
1025 {
1026         socket_info_t *s = &socket[sock];
1027         u_char map;
1028         int error;
1029
1030         if (sock >= TOTAL_NUM_OF_SOCKETS) {
1031                 DEBUG(4, "pccf_4xx: set_io_map(%d) failed\n", sock);
1032                 return -EINVAL;
1033         }
1034
1035         DEBUG(1, "pccf_4xx: SetIOMap(%d, %d, %#2.2x, %d ns, "
1036               "%#4.4x-%#4.4x)\n", sock, io->map, io->flags,
1037               io->speed, io->start, io->stop);
1038
1039         map = io->map;
1040
1041         if ((io->map >= PCMCIA_IO_WIN_NO) ||
1042             (io->start >= PCCF_4XX_IO_WINSIZE) ||
1043             (io->stop >= PCCF_4XX_IO_WINSIZE) || (io->stop < io->start)) {
1044                 printk(KERN_ERR "pccf_4xx: set_io_map: Illegal "
1045                        "IO map: map = %d, start = 0x%08x, stop = 0x%08x\n",
1046                        io->map, io->start, io->stop);
1047                 return -EINVAL;
1048         }
1049
1050         if (io->flags & MAP_ACTIVE) {
1051
1052                 if (io->flags & MAP_WRPROT) {
1053                         if ((error = write_protect_io(sock, io->map)))
1054                                 return error;
1055                 } else {
1056                         if ((error = write_unprotect_io(sock, io->map)))
1057                                 return error;
1058                 }
1059
1060                 if (io->flags & MAP_16BIT) {
1061                         pcmcia_16bit();
1062                 } else if (io->flags & MAP_AUTOSZ) {
1063                         pcmcia_autosz();
1064                 } else {
1065                         pcmcia_8bit();
1066                 }
1067
1068                 /* MAP_0WS      ignored
1069                    MAP_USE_WAIT ignored (assumed)
1070                    MAP_PREFECTH ignored (could be implemented with some
1071                    MMU gyrations)
1072
1073                    speed        ignored */
1074         }
1075
1076         /* Copy the struct and modify the flags to be accurate based on our
1077            limitations. */
1078
1079         s->io_win[io->map] = *io;
1080         s->io_win[io->map].flags &=
1081             (MAP_ACTIVE | MAP_WRPROT | MAP_AUTOSZ | MAP_16BIT);
1082
1083         return 0;
1084 }
1085
1086 /* Copy the memory map back to the caller */
1087
1088 static int
1089 pccf_4xx_get_mem_map(unsigned int sock, struct pccard_mem_map *mem)
1090 {
1091         if (sock >= TOTAL_NUM_OF_SOCKETS) {
1092                 DEBUG(4, "pccf_4xx: get_mem_map(%d) failed\n", sock);
1093                 return -EINVAL;
1094         }
1095
1096         if (mem->map >= PCMCIA_MEM_WIN_NO) {
1097                 printk(KERN_ERR "pccf_4xx: Driver requested memory map %d "
1098                        "which is not supported by this controller\n", mem->map);
1099                 return -EINVAL;
1100         }
1101
1102         *mem = socket[sock].mem_win[mem->map];  /* copy the struct */
1103
1104         DEBUG(1, "pccf_4xx: GetMemMap(%d, %d) = %#2.2x, %d ns, %#5.5lx-%#5."
1105               "5lx, %#5.5x\n", sock, mem->map, mem->flags, mem->speed,
1106               mem->sys_start, mem->sys_stop, mem->card_start);
1107
1108         return 0;
1109 }
1110
1111 /* Set the memory map. */
1112
1113 static int
1114 pccf_4xx_set_mem_map(unsigned int sock, struct pccard_mem_map *mem)
1115 {
1116         socket_info_t *s = &socket[sock];
1117         int error;
1118         if (sock >= TOTAL_NUM_OF_SOCKETS) {
1119                 DEBUG(4, "pccf_4xx: set_mem_map(%d) failed\n", sock);
1120                 return -EINVAL;
1121         }
1122
1123         if ((mem->map >= PCMCIA_MEM_WIN_NO) ||
1124             (mem->sys_start > mem->sys_stop) ||
1125             ((mem->sys_stop - mem->sys_start) >= PCCF_4XX_MEM_WINSIZE) ||
1126             ((mem->card_start + (mem->sys_stop - mem->sys_start)) >=
1127              PCCF_4XX_MEM_WINSIZE)) {
1128                 DEBUG(4, "pccf_4xx: set_mem_map: Illegal "
1129                       "memory map: map = %d, start = 0x%08lx, stop = 0x%08lx "
1130                       "card_start = 0x%08x\n",
1131                       mem->map, mem->sys_start, mem->sys_stop, mem->card_start);
1132                 return -EINVAL;
1133         }
1134
1135         DEBUG(1, "pccf_4xx: SetMemMap[entry]"
1136               "(%d, %d, %#2.2x, %d ns, %#8.8lx-%#8.8"
1137               "lx, %#5.5x)\n", sock, mem->map, mem->flags, mem->speed,
1138               mem->sys_start, mem->sys_stop, mem->card_start);
1139
1140         if (mem->flags & MAP_ACTIVE) {
1141                 mem->sys_stop -= mem->sys_start;
1142                 if (mem->flags & MAP_ATTRIB)
1143                         mem->sys_start = PCMCIA_ATTRIB_PADDR + mem->card_start;
1144                 else
1145                         mem->sys_start = PCCF_4XX_MEM_PADDR + mem->card_start;
1146                 mem->sys_stop += mem->sys_start;
1147         }
1148
1149         DEBUG(2, "pccf_4xx: SetMemMap[exit]"
1150               "(%d, %d, %#2.2x, %d ns, %#8.8lx-%#8.8"
1151               "lx, %#5.5x)\n", sock, mem->map, mem->flags, mem->speed,
1152               mem->sys_start, mem->sys_stop, mem->card_start);
1153
1154         if (mem->flags & MAP_ACTIVE) {
1155
1156                 if (mem->flags & MAP_WRPROT) {
1157                         if ((error = write_protect_mem(sock, mem->map)))
1158                                 return error;
1159                 } else {
1160                         if ((error = write_unprotect_mem(sock, mem->map)))
1161                                 return error;
1162                 }
1163
1164                 if (mem->flags & MAP_16BIT) {
1165                         pcmcia_16bit();
1166                 } else if (mem->flags & MAP_AUTOSZ) {
1167                         pcmcia_autosz();
1168                 } else {
1169                         pcmcia_8bit();
1170                 }
1171
1172                 /* MAP_0WS      ignored
1173                    MAP_USE_WAIT ignored (assumed) */
1174
1175                 if (mem->speed > MIN_SPEED) {
1176                         printk(KERN_ERR "pccf_4xx: Memory speed %d ns is not "
1177                                "supported.\n", mem->speed);
1178                         return -EINVAL;
1179                 }
1180         }
1181
1182         /* Copy the struct and modify the flags to be accurate based on our
1183            limitations. */
1184
1185         s->mem_win[mem->map] = *mem;
1186         s->mem_win[mem->map].flags &=
1187             (MAP_ACTIVE | MAP_WRPROT | MAP_AUTOSZ | MAP_16BIT);
1188
1189         return 0;
1190 }
1191
1192 static int
1193 pccf_4xx_sock_init(unsigned int s)
1194 {
1195         DEBUG(3, "pccf_4xx: sock_init(%d)\n", s);
1196
1197         pccf_4xx_set_socket(s, &dead_socket);
1198         return 0;
1199
1200 }
1201
1202 static int
1203 pccf_4xx_suspend(unsigned int s)
1204 {
1205         return (pccf_4xx_set_socket(s, &dead_socket));
1206 }
1207 static void
1208 pccf_4xx_proc_setup(unsigned int sock, struct proc_dir_entry *base)
1209 {
1210 }
1211
1212 /* Service table and service dispatching */
1213
1214 static struct pccard_operations pccf_4xx_services = {
1215         &pccf_4xx_sock_init,
1216         &pccf_4xx_suspend,
1217         &pccf_4xx_register_callback,
1218         &pccf_4xx_inquire_socket,
1219         &pccf_4xx_get_status,
1220         &pccf_4xx_get_socket,
1221         &pccf_4xx_set_socket,
1222         &pccf_4xx_get_io_map,
1223         &pccf_4xx_set_io_map,
1224         &pccf_4xx_get_mem_map,
1225         &pccf_4xx_set_mem_map,
1226         &pccf_4xx_proc_setup
1227 };
1228
1229 /* The initialization/exit functions. */
1230
1231 static int __init
1232 init_pccf_4xx(void)
1233 {
1234         servinfo_t serv;
1235         int error;
1236
1237         printk(KERN_INFO "%s\n", version);
1238
1239         DEBUG(0, "pccf_4xx: Physical base address is 0x%08lx\n", PCCF_4XX_PADDR);
1240         DEBUG(0, "pccf_4xx: Virtual base addresses: macro=0x%p, mem=0x%lx"
1241               " io=0x%lx\n", pccf_4xx_macro_vaddr, _ISA_MEM_BASE, _IO_BASE);
1242
1243         CardServices(GetCardServicesInfo, &serv);
1244         if (serv.Revision != CS_RELEASE_CODE) {
1245                 printk(KERN_NOTICE
1246                        "pccf_4xx: Card services version does not match!\n"
1247                        "Card Services is 0x%04x, CS_RELEASE_CODE is 0x%04x\n",
1248                        serv.Revision, CS_RELEASE_CODE);
1249                 return -EBUSY;
1250         }
1251
1252         pcmcia_mrr();           /* Reset the PCCF Macro */
1253         poweroff();             /* Make sure socket is powered down */
1254         pcmcia_mask_cdi();      /* Mask card-detect interrupt */
1255         pcmcia_mask_sti();      /* Mask status change interrupt */
1256         pcmcia_clr_cdi();       /* Clear card detect status */
1257
1258         /* Note that the PCMCIA macro interrupts are not shared. */
1259
1260         socket[0].intr = PCCF_4XX_MACRO_IRQ;
1261
1262         if ((error = request_irq(PCCF_4XX_MACRO_IRQ, pccf_4xx_interrupt, 0, "pcmcia",
1263                                  &socket[0])) != 0) {
1264                 printk(KERN_ERR "pccf_4xx: IRQ %d not available!\n", PCCF_4XX_MACRO_IRQ);
1265                 return error;
1266         }
1267
1268         if ((error = register_ss_entry(sockets, &pccf_4xx_services)) != 0) {
1269                 printk(KERN_ERR "pccf_4xx: register_ss_entry() failed!\n");
1270                 goto error_ss;
1271         }
1272
1273         return 0;
1274
1275       error_ss:
1276         free_irq(socket[0].intr, &socket[0]);
1277         return error;
1278 }
1279
1280 static void __exit
1281 exit_pccf_4xx(void)
1282 {
1283         poweroff();
1284         pcmcia_mrr();
1285
1286         request_module("pcmcia_core");
1287
1288         unregister_ss_entry(&pccf_4xx_services);
1289
1290         free_irq(socket[0].intr, &socket[0]);
1291 }
1292
1293 module_init(init_pccf_4xx);
1294 module_exit(exit_pccf_4xx);