1 /* Device driver for the IBM 4xx PCMCIA/CF+ Interface Macro (PCCF)
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.
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.
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
17 * Copyright (C) 2001, International Business Machines Corporation
18 * All Rights Reserved.
19 * Copyright (C) 2002 MontaVista Software, Inc. <source@mvista.com>
21 * Eric Van Hensbegren <bergevan@us.ibm.com>
22 * IBM Austin Research Lab
24 * Based on original code by Magnus Damm for mpc8xx series driver
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)
30 * August, 2002 - Conversion to standalone in-kernel driver by Todd
31 * Poynor (MontaVista Software)
32 ****************************************************************************
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
43 1 - Cards that request 5 V will be powered by 3.3 V instead. See below for
48 0 - [ Default ] Drivers that request write-protected regions will fail
49 unless the configuration can actually write protect the region.
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.
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.
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.
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.
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).
87 PCCF supports a single PCMCIA/CF slot.
89 EBC Setup and Memory Map
90 =========================
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.
105 The PCCF macro maps a 32 MB physical address space as indicated below.
106 Offsets are relative to the physical base address.
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
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.
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.
128 Legacy IO and Address Mapping
129 =============================
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.
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.
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.
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#.
154 The Pecan FPGA implementation of PCCF supports both 3.3 V and 5 V operation,
155 and both VS1# and VS2#.
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
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
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.
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.
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
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.
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.
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. ]
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.
209 ****************************************************************************/
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>
218 #include <asm/bitops.h>
219 #include <asm/segment.h>
220 #include <asm/system.h>
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>
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>
238 #include <asm/byteorder.h>
239 #include <asm/pccf_4xx.h>
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");
248 static int pwr5by3 = 0;
249 static int ignore_wrprot = 0;
251 static const char *version =
252 "pccf_4xx.c $Revision: 1.1.1.1 $ $Date: 2005/04/11 02:50:33 $ (Eric Van Hensbergen)";
254 #define PCMCIA_DEBUG 0
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)
263 #define DEBUG(n, args...)
268 #define VCC5V_SUPPORT 1
270 /* Minimum bus cycle time (in ns) */
272 #define MIN_SPEED 300
274 #define PCMCIA_ATTRIB_OFFSET 0x00800000
275 #define PCMCIA_ATTRIB_PADDR (PCCF_4XX_PADDR + PCMCIA_ATTRIB_OFFSET)
277 #define PCMCIA_MEM_WIN_NO 1
278 #define PCMCIA_IO_WIN_NO 2
280 #define PCMCIA_CTRL(offset)\
281 ((volatile unsigned short *)((u8 *) pccf_4xx_macro_vaddr + (offset)))
283 /* PCCF control registers are big-endian */
285 #define GET_PCMCIA_CTRL(offset) (in_be16(PCMCIA_CTRL(offset)))
286 #define SET_PCMCIA_CTRL(value, offset) (out_be16(PCMCIA_CTRL(offset), value))
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 */
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)
301 #define get_field16(reg, hi, lo)\
302 ((reg >> (15 - (lo))) & ~(-1 << ((lo) - (hi) + 1)))
304 #define make_field16(val, hi, lo)\
305 (((val) & ~(-1 << ((lo) - (hi) + 1))) << (15 - (lo)))
306 #endif /* get_field16 */
309 #define get_field32(reg, hi, lo)\
310 ((reg >> (31 - (lo))) & ~(-1 << ((lo) - (hi) + 1)))
312 #define make_field32(val, hi, lo)\
313 (((val) & ~(-1 << ((lo) - (hi) + 1))) << (31 - (lo)))
315 #define set_field32(word, hi, lo, val)\
316 (((word) & ~(make_field32(0xffffffff, hi, lo))) | make_field32(val, hi, lo))
317 #endif /* get_field32 */
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)
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)
332 #define PCMCIA_ISR_STSCHG(isr) get_field16(isr, 6, 6)
333 #define PCMCIA_ISR_DETECT(isr) get_field16(isr, 7, 7)
335 #define PCMCIA_ICR_STSCHG(icr) get_field16(icr, 4, 4)
336 #define PCMCIA_ICR_DETECT(icr) get_field16(icr, 5, 5)
338 /* These are values used to represent voltage levels */
343 /****************************************************************************
344 PCCF control routines
345 ****************************************************************************/
347 /* Pecan and Beech Pass 1 use the PCCF macro for power control (although Beech
348 Pass 1 doesn't support +5V.
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
361 #if defined(CONFIG_BEECH)
367 *beech_fpga_reg_4 &= ~FPGA_REG_4_PCMCIA_5V;
368 restore_flags(flags);
373 unsigned short ccr = PCMCIA_CCR;
375 ccr &= ~0x0200; /* -+3V */
376 ccr &= ~0x0100; /* -+5V */
384 unsigned short ccr = PCMCIA_CCR;
388 ccr |= 0x0200; /* ++3V */
389 ccr &= ~0x0100; /* -+5V */
396 unsigned short ccr = PCMCIA_CCR;
400 ccr &= ~0x0200; /* -+3V */
401 ccr |= 0x0100; /* ++5V */
404 #if defined(CONFIG_BEECH)
410 *beech_fpga_reg_4 |= FPGA_REG_4_PCMCIA_5V;
411 restore_flags(flags);
418 { /* Assert card reset for 10 us */
419 unsigned short ccr = PCMCIA_CCR;
421 ccr |= 0x0080; /* Reset */
431 { /* Reset the PCCF macro */
432 SET_PCMCIA_MRR(0xffff);
437 { /* Set memory mode */
438 unsigned short ccr = PCMCIA_CCR;
446 { /* Set memory and IO mode */
447 unsigned short ccr = PCMCIA_CCR;
456 { /* Clear the card-detect interrupt */
457 unsigned short icr = PCMCIA_ICR;
467 pcmcia_unmask_cdi(void)
468 { /* Unmask the card-detect interrupt */
469 unsigned short icr = PCMCIA_ICR;
476 pcmcia_unmask_sti(void)
477 { /* Unmask the status-change interrupt */
478 unsigned short icr = PCMCIA_ICR;
485 pcmcia_mask_cdi(void)
486 { /* Mask the card-detect interrupt */
487 unsigned short icr = PCMCIA_ICR;
494 pcmcia_mask_sti(void)
495 { /* Mask the status-change interrupt */
496 unsigned short icr = PCMCIA_ICR;
504 { /* Set 16-bit mode */
505 unsigned short ccr = PCMCIA_CCR;
513 { /* Set IOIS16# mode */
514 unsigned short ccr = PCMCIA_CCR;
523 { /* Set 8-bit mode */
524 unsigned short ccr = PCMCIA_CCR;
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
535 typedef struct socket_info_t {
537 void (*handler) (void *info, u_int events);
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];
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.
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
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 */
560 PCCF_4XX_CARD_IRQ, /* Single fixed socket interrupt */
561 NULL, /* No CardBus support */
562 NULL /* No virtual bus operations */
565 /* Socket parameters and data */
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];
571 /****************************************************************************
572 Configuration-specific code
573 ****************************************************************************/
575 /* Voltage control. See comments at the beginning of the file.
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
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
596 printk(KERN_WARNING "pccf_4xx: Warning: Powering 5 V "
597 "card with 3.3 V. Good Luck!\n");
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");
611 printk(KERN_ERR "pccf_4xx: Illegal Vcc voltage = %d\n", *Vcc);
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
636 set_Vpp(int *Vcc, int *Vpp)
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);
646 DEBUG(0, "pccf_4xx: Setting Vpp = Vcc = "
647 "%d.%d\n", *Vcc / 10, *Vcc % 10);
656 int Vcc = 0, Vpp = 0;
666 set_voltage(int *Vcc, int *Vpp)
668 if ((*Vcc == 0) && (*Vpp == 0))
672 if (set_Vpp(Vcc, Vpp))
681 /* Write protection is currently unimplemented */
684 write_protect_io(unsigned int sock, u_char map)
687 printk(KERN_WARNING "pccf_4xx: Request to write protect IO "
688 "map %d on socket %d will be ignored.\n", map, sock);
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",
703 write_unprotect_io(unsigned int sock, u_char map)
709 write_protect_mem(unsigned int sock, u_char map)
712 printk(KERN_WARNING "pccf_4xx: Request to write protect "
713 "memory map %d on socket %d will be ignored.\n",
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",
729 write_unprotect_mem(unsigned int sock, u_char map)
734 /****************************************************************************
736 ****************************************************************************/
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.
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
749 static u_int pending_events[TOTAL_NUM_OF_SOCKETS];
750 static spinlock_t pending_event_lock = SPIN_LOCK_UNLOCKED;
753 pccf_4xx_task(void *dummy)
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);
764 if (events && socket[i].handler)
765 socket[i].handler(socket[i].info, events);
769 static struct tq_struct pccf_4xx_tqentry = {
770 routine:pccf_4xx_task
774 pccf_4xx_interrupt(int irq, void *dev, struct pt_regs *regs)
777 unsigned short isr = PCMCIA_ISR;
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);
783 if (PCMCIA_ISR_DETECT(isr)) {
787 } else if (PCMCIA_ISR_STSCHG(isr))
792 DEBUG(2, "pccf_4xx: socket 0 event 0x%02x\n", events);
795 spin_lock(&pending_event_lock);
796 pending_events[0] |= events;
797 spin_unlock(&pending_event_lock);
798 schedule_task(&pccf_4xx_tqentry);
802 /* This routine registers a callback to be called when the socket driver
803 receives card status change events. */
806 pccf_4xx_register_callback(unsigned int sock,
807 void (*handler) (void *, unsigned int), void *info)
809 DEBUG(4, "pccf_4xx: register_callback(%d) = 0x%p, 0x%p\n",
810 sock, handler, info);
812 if (sock >= TOTAL_NUM_OF_SOCKETS)
815 socket[sock].handler = handler;
816 socket[sock].info = info;
817 if (handler == NULL) {
825 /* The capabilities are copied to the caller. */
828 pccf_4xx_inquire_socket(unsigned int sock, socket_cap_t * cap)
830 if (sock >= TOTAL_NUM_OF_SOCKETS) {
831 DEBUG(4, "pccf_4xx: inquire_socket(%d) failed\n", sock);
835 DEBUG(0, "pccf_4xx: inquire_socket(%d)\n", sock);
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. */
846 pccf_4xx_get_status(unsigned int sock, u_int * value)
848 unsigned short csr = PCMCIA_CSR;
849 unsigned short isr = PCMCIA_ISR;
852 if (sock >= TOTAL_NUM_OF_SOCKETS) {
853 DEBUG(4, "pccf_4xx: get_status(%d) failed\n", sock);
857 if (PCMCIA_CSR_DETECT(csr)) {
860 if (PCMCIA_CSR_IO(csr)) {
861 if (PCMCIA_ISR_STSCHG(isr))
864 if (PCMCIA_CSR_READY(csr)) {
869 if (PCMCIA_CSR_PWR(csr)) {
870 *value |= SS_POWERON;
873 switch ((PCMCIA_CSR_VS1(csr) << 1) | PCMCIA_CSR_VS2(csr)) {
874 case 3: /* 5V card */
884 DEBUG(1, "pccf_4xx: GetStatus(%d) = %#4.4x\n", sock, *value);
888 /* Copy the socket state structure. */
891 pccf_4xx_get_socket(unsigned int sock, socket_state_t * state)
893 if (sock >= TOTAL_NUM_OF_SOCKETS) {
894 DEBUG(4, "pccf_4xx: get_socket(%d) failed\n", sock);
898 *state = socket[sock].state; /* copy the whole structure */
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);
906 /* Set the socket parameters, and apply power to the slot.
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
914 pccf_4xx_set_socket(unsigned int sock, socket_state_t * state)
916 int Vcc = state->Vcc;
917 int Vpp = state->Vpp;
919 if (sock >= TOTAL_NUM_OF_SOCKETS) {
920 DEBUG(4, "pccf_4xx: set_socket(%d) failed\n", sock);
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);
928 /* Apply/remove power */
930 set_voltage(&Vcc, &Vpp);
932 /* Decode csc_mask requests. */
934 if (state->csc_mask & SS_DETECT)
937 pcmcia_mask_cdi(); /* This would be extremely bizarre */
939 if (state->csc_mask & SS_STSCHG)
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");
952 /* Perform flag actions */
954 if (state->flags & SS_RESET) {
956 printk(KERN_WARNING "pccf_4xx: Request to reset "
957 " unpowered slot ignored\n");
962 if (state->flags & SS_IOCARD) {
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);
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 "
979 /* SS_OUTPUT_ENA -- Nothing to do here in any supported
981 SS_PWR_AUTO -- Not supported by the controller */
983 /* Copy the state to the socket */
985 socket[sock].state = *state;
990 /* Copy the IO map back to the caller */
993 pccf_4xx_get_io_map(unsigned int sock, struct pccard_io_map *io)
997 if (sock >= TOTAL_NUM_OF_SOCKETS) {
998 DEBUG(4, "pccf_4xx: get_io_map(%d) failed\n", sock);
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);
1009 *io = socket[sock].io_win[io->map];
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);
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.
1020 There's nothing really to "turn on" here. We presume the EBC is always set
1021 up and ready to go. */
1024 pccf_4xx_set_io_map(unsigned int sock, struct pccard_io_map *io)
1026 socket_info_t *s = &socket[sock];
1030 if (sock >= TOTAL_NUM_OF_SOCKETS) {
1031 DEBUG(4, "pccf_4xx: set_io_map(%d) failed\n", sock);
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);
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);
1050 if (io->flags & MAP_ACTIVE) {
1052 if (io->flags & MAP_WRPROT) {
1053 if ((error = write_protect_io(sock, io->map)))
1056 if ((error = write_unprotect_io(sock, io->map)))
1060 if (io->flags & MAP_16BIT) {
1062 } else if (io->flags & MAP_AUTOSZ) {
1069 MAP_USE_WAIT ignored (assumed)
1070 MAP_PREFECTH ignored (could be implemented with some
1076 /* Copy the struct and modify the flags to be accurate based on our
1079 s->io_win[io->map] = *io;
1080 s->io_win[io->map].flags &=
1081 (MAP_ACTIVE | MAP_WRPROT | MAP_AUTOSZ | MAP_16BIT);
1086 /* Copy the memory map back to the caller */
1089 pccf_4xx_get_mem_map(unsigned int sock, struct pccard_mem_map *mem)
1091 if (sock >= TOTAL_NUM_OF_SOCKETS) {
1092 DEBUG(4, "pccf_4xx: get_mem_map(%d) failed\n", sock);
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);
1102 *mem = socket[sock].mem_win[mem->map]; /* copy the struct */
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);
1111 /* Set the memory map. */
1114 pccf_4xx_set_mem_map(unsigned int sock, struct pccard_mem_map *mem)
1116 socket_info_t *s = &socket[sock];
1118 if (sock >= TOTAL_NUM_OF_SOCKETS) {
1119 DEBUG(4, "pccf_4xx: set_mem_map(%d) failed\n", sock);
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);
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);
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;
1145 mem->sys_start = PCCF_4XX_MEM_PADDR + mem->card_start;
1146 mem->sys_stop += mem->sys_start;
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);
1154 if (mem->flags & MAP_ACTIVE) {
1156 if (mem->flags & MAP_WRPROT) {
1157 if ((error = write_protect_mem(sock, mem->map)))
1160 if ((error = write_unprotect_mem(sock, mem->map)))
1164 if (mem->flags & MAP_16BIT) {
1166 } else if (mem->flags & MAP_AUTOSZ) {
1173 MAP_USE_WAIT ignored (assumed) */
1175 if (mem->speed > MIN_SPEED) {
1176 printk(KERN_ERR "pccf_4xx: Memory speed %d ns is not "
1177 "supported.\n", mem->speed);
1182 /* Copy the struct and modify the flags to be accurate based on our
1185 s->mem_win[mem->map] = *mem;
1186 s->mem_win[mem->map].flags &=
1187 (MAP_ACTIVE | MAP_WRPROT | MAP_AUTOSZ | MAP_16BIT);
1193 pccf_4xx_sock_init(unsigned int s)
1195 DEBUG(3, "pccf_4xx: sock_init(%d)\n", s);
1197 pccf_4xx_set_socket(s, &dead_socket);
1203 pccf_4xx_suspend(unsigned int s)
1205 return (pccf_4xx_set_socket(s, &dead_socket));
1208 pccf_4xx_proc_setup(unsigned int sock, struct proc_dir_entry *base)
1212 /* Service table and service dispatching */
1214 static struct pccard_operations pccf_4xx_services = {
1215 &pccf_4xx_sock_init,
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
1229 /* The initialization/exit functions. */
1237 printk(KERN_INFO "%s\n", version);
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);
1243 CardServices(GetCardServicesInfo, &serv);
1244 if (serv.Revision != CS_RELEASE_CODE) {
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);
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 */
1258 /* Note that the PCMCIA macro interrupts are not shared. */
1260 socket[0].intr = PCCF_4XX_MACRO_IRQ;
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);
1268 if ((error = register_ss_entry(sockets, &pccf_4xx_services)) != 0) {
1269 printk(KERN_ERR "pccf_4xx: register_ss_entry() failed!\n");
1276 free_irq(socket[0].intr, &socket[0]);
1286 request_module("pcmcia_core");
1288 unregister_ss_entry(&pccf_4xx_services);
1290 free_irq(socket[0].intr, &socket[0]);
1293 module_init(init_pccf_4xx);
1294 module_exit(exit_pccf_4xx);