2 * (C) Copyright 2000-2006
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
7 ********************************************************************
9 * Lots of code copied from:
11 * m8xx_pcmcia.c - Linux PCMCIA socket driver for the mpc8xx series.
12 * (C) 1999-2000 Magnus Damm <damm@bitsmart.com>
14 * "The ExCA standard specifies that socket controllers should provide
15 * two IO and five memory windows per socket, which can be independently
16 * configured and positioned in the host address space and mapped to
17 * arbitrary segments of card address space. " - David A Hinds. 1999
19 * This controller does _not_ meet the ExCA standard.
21 * m8xx pcmcia controller brief info:
22 * + 8 windows (attrib, mem, i/o)
23 * + up to two slots (SLOT_A and SLOT_B)
24 * + inputpins, outputpins, event and mask registers.
25 * - no offset register. sigh.
27 * Because of the lacking offset register we must map the whole card.
28 * We assign each memory window PCMCIA_MEM_WIN_SIZE address space.
29 * Make sure there is (PCMCIA_MEM_WIN_SIZE * PCMCIA_MEM_WIN_NO
30 * * PCMCIA_SOCKETS_NO) bytes at PCMCIA_MEM_WIN_BASE.
31 * The i/o windows are dynamically allocated at PCMCIA_IO_WIN_BASE.
32 * They are maximum 64KByte each...
46 /* -------------------------------------------------------------------- */
48 #if defined(CONFIG_CMD_PCMCIA)
50 extern int pcmcia_on (void);
51 extern int pcmcia_off (void);
53 int do_pinit (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
58 printf ("Usage: pinit {on | off}\n");
61 if (strcmp(argv[1],"on") == 0) {
63 } else if (strcmp(argv[1],"off") == 0) {
64 rcode = pcmcia_off ();
66 printf ("Usage: pinit {on | off}\n");
74 pinit, 2, 0, do_pinit,
76 "on - power on PCMCIA socket\n"
77 "pinit off - power off PCMCIA socket"
82 /* -------------------------------------------------------------------- */
84 #undef CHECK_IDE_DEVICE
86 #if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_8xx_PCCARD)
87 #define CHECK_IDE_DEVICE
90 #if defined(CONFIG_PXA_PCMCIA)
91 #define CHECK_IDE_DEVICE
94 #ifdef CHECK_IDE_DEVICE
96 int ide_devices_found;
97 static uchar *known_cards[] = {
98 (uchar *)"ARGOSY PnPIDE D5",
102 #define MAX_TUPEL_SZ 512
103 #define MAX_FEATURES 4
105 #define MAX_IDENT_CHARS 64
106 #define MAX_IDENT_FIELDS 4
110 static void print_funcid (int func)
114 case CISTPL_FUNCID_MULTI:
115 puts (" Multi-Function");
117 case CISTPL_FUNCID_MEMORY:
120 case CISTPL_FUNCID_SERIAL:
121 puts (" Serial Port");
123 case CISTPL_FUNCID_PARALLEL:
124 puts (" Parallel Port");
126 case CISTPL_FUNCID_FIXED:
127 puts (" Fixed Disk");
129 case CISTPL_FUNCID_VIDEO:
130 puts (" Video Adapter");
132 case CISTPL_FUNCID_NETWORK:
133 puts (" Network Adapter");
135 case CISTPL_FUNCID_AIMS:
138 case CISTPL_FUNCID_SCSI:
139 puts (" SCSI Adapter");
148 static void print_fixed (volatile uchar *p)
156 case CISTPL_FUNCE_IDE_IFACE:
157 { uchar iface = *(p+2);
159 puts ((iface == CISTPL_IDE_INTERFACE) ? " IDE" : " unknown");
160 puts (" interface ");
163 case CISTPL_FUNCE_IDE_MASTER:
164 case CISTPL_FUNCE_IDE_SLAVE:
168 puts ((f1 & CISTPL_IDE_SILICON) ? " [silicon]" : " [rotating]");
170 if (f1 & CISTPL_IDE_UNIQUE)
173 puts ((f1 & CISTPL_IDE_DUAL) ? " [dual]" : " [single]");
175 if (f2 & CISTPL_IDE_HAS_SLEEP)
178 if (f2 & CISTPL_IDE_HAS_STANDBY)
181 if (f2 & CISTPL_IDE_HAS_IDLE)
184 if (f2 & CISTPL_IDE_LOW_POWER)
185 puts (" [low power]");
187 if (f2 & CISTPL_IDE_REG_INHIBIT)
188 puts (" [reg inhibit]");
190 if (f2 & CISTPL_IDE_HAS_INDEX)
193 if (f2 & CISTPL_IDE_IOIS16)
202 static int identify (volatile uchar *p)
204 uchar id_str[MAX_IDENT_CHARS];
211 return (0); /* Don't know */
216 for (i=0; i<=4 && !done; ++i, p+=2) {
217 while ((data = *p) != '\0') {
223 if (t == &id_str[MAX_IDENT_CHARS-1]) {
233 while (--t > id_str) {
239 puts ((char *)id_str);
242 for (card=known_cards; *card; ++card) {
243 debug ("## Compare against \"%s\"\n", *card);
244 if (strcmp((char *)*card, (char *)id_str) == 0) { /* found! */
245 debug ("## CARD FOUND ##\n");
250 return (0); /* don't know */
253 int check_ide_device (int slot)
255 volatile uchar *ident = NULL;
256 volatile uchar *feature_p[MAX_FEATURES];
257 volatile uchar *p, *start, *addr;
261 ushort config_base = 0;
265 addr = (volatile uchar *)(CONFIG_SYS_PCMCIA_MEM_ADDR +
266 CONFIG_SYS_PCMCIA_MEM_SIZE * (slot * 4));
267 debug ("PCMCIA MEM: %08lX\n", (ulong)addr);
269 start = p = (volatile uchar *) addr;
271 while ((p - start) < MAX_TUPEL_SZ) {
275 if (code == 0xFF) { /* End of chain */
280 #if defined(DEBUG) && (DEBUG > 1)
281 { volatile uchar *q = p;
282 printf ("\nTuple code %02x length %d\n\tData:",
285 for (i = 0; i < len; ++i) {
286 printf (" %02x", *q);
296 /* Fix for broken SanDisk which may have 0x80 bit set */
300 if (n_features < MAX_FEATURES)
301 feature_p[n_features++] = p;
304 config_base = (*(p+6) << 8) + (*(p+4));
305 debug ("\n## Config_base = %04x ###\n", config_base);
312 found = identify (ident);
314 if (func_id != ((uchar)~0)) {
315 print_funcid (func_id);
317 if (func_id == CISTPL_FUNCID_FIXED)
320 return (1); /* no disk drive */
323 for (i=0; i<n_features; ++i) {
324 print_fixed (feature_p[i]);
328 printf ("unknown card type\n");
332 ide_devices_found |= (1 << slot);
336 /* set I/O area in config reg -> only valid for ARGOSY D5!!! */
337 *((uchar *)(addr + config_base)) = 1;
340 printf("\n## Config_base = %04x ###\n", config_base);
341 printf("Configuration Option Register: %02x @ %x\n", readb(addr + config_base), addr + config_base);
342 printf("Card Configuration and Status Register: %02x\n", readb(addr + config_base + 2));
343 printf("Pin Replacement Register Register: %02x\n", readb(addr + config_base + 4));
344 printf("Socket and Copy Register: %02x\n", readb(addr + config_base + 6));
349 #endif /* CHECK_IDE_DEVICE */