1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2000-2006
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
6 ********************************************************************
8 * Lots of code copied from:
10 * m8xx_pcmcia.c - Linux PCMCIA socket driver for the mpc8xx series.
11 * (C) 1999-2000 Magnus Damm <damm@bitsmart.com>
13 * "The ExCA standard specifies that socket controllers should provide
14 * two IO and five memory windows per socket, which can be independently
15 * configured and positioned in the host address space and mapped to
16 * arbitrary segments of card address space. " - David A Hinds. 1999
18 * This controller does _not_ meet the ExCA standard.
20 * m8xx pcmcia controller brief info:
21 * + 8 windows (attrib, mem, i/o)
22 * + up to two slots (SLOT_A and SLOT_B)
23 * + inputpins, outputpins, event and mask registers.
24 * - no offset register. sigh.
26 * Because of the lacking offset register we must map the whole card.
27 * We assign each memory window PCMCIA_MEM_WIN_SIZE address space.
28 * Make sure there is (PCMCIA_MEM_WIN_SIZE * PCMCIA_MEM_WIN_NO
29 * * PCMCIA_SOCKETS_NO) bytes at PCMCIA_MEM_WIN_BASE.
30 * The i/o windows are dynamically allocated at PCMCIA_IO_WIN_BASE.
31 * They are maximum 64KByte each...
45 /* -------------------------------------------------------------------- */
47 #if defined(CONFIG_CMD_PCMCIA)
49 extern int pcmcia_on (void);
50 extern int pcmcia_off (void);
52 int do_pinit (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
57 printf ("Usage: pinit {on | off}\n");
60 if (strcmp(argv[1],"on") == 0) {
62 } else if (strcmp(argv[1],"off") == 0) {
63 rcode = pcmcia_off ();
65 printf ("Usage: pinit {on | off}\n");
73 pinit, 2, 0, do_pinit,
75 "on - power on PCMCIA socket\n"
76 "pinit off - power off PCMCIA socket"
81 /* -------------------------------------------------------------------- */
83 #undef CHECK_IDE_DEVICE
85 #if defined(CONFIG_PXA_PCMCIA)
86 #define CHECK_IDE_DEVICE
89 #ifdef CHECK_IDE_DEVICE
91 int ide_devices_found;
92 static uchar *known_cards[] = {
93 (uchar *)"ARGOSY PnPIDE D5",
97 #define MAX_TUPEL_SZ 512
98 #define MAX_FEATURES 4
100 #define MAX_IDENT_CHARS 64
101 #define MAX_IDENT_FIELDS 4
105 static void print_funcid (int func)
109 case CISTPL_FUNCID_MULTI:
110 puts (" Multi-Function");
112 case CISTPL_FUNCID_MEMORY:
115 case CISTPL_FUNCID_SERIAL:
116 puts (" Serial Port");
118 case CISTPL_FUNCID_PARALLEL:
119 puts (" Parallel Port");
121 case CISTPL_FUNCID_FIXED:
122 puts (" Fixed Disk");
124 case CISTPL_FUNCID_VIDEO:
125 puts (" Video Adapter");
127 case CISTPL_FUNCID_NETWORK:
128 puts (" Network Adapter");
130 case CISTPL_FUNCID_AIMS:
133 case CISTPL_FUNCID_SCSI:
134 puts (" SCSI Adapter");
143 static void print_fixed (volatile uchar *p)
151 case CISTPL_FUNCE_IDE_IFACE:
152 { uchar iface = *(p+2);
154 puts ((iface == CISTPL_IDE_INTERFACE) ? " IDE" : " unknown");
155 puts (" interface ");
158 case CISTPL_FUNCE_IDE_MASTER:
159 case CISTPL_FUNCE_IDE_SLAVE:
163 puts ((f1 & CISTPL_IDE_SILICON) ? " [silicon]" : " [rotating]");
165 if (f1 & CISTPL_IDE_UNIQUE)
168 puts ((f1 & CISTPL_IDE_DUAL) ? " [dual]" : " [single]");
170 if (f2 & CISTPL_IDE_HAS_SLEEP)
173 if (f2 & CISTPL_IDE_HAS_STANDBY)
176 if (f2 & CISTPL_IDE_HAS_IDLE)
179 if (f2 & CISTPL_IDE_LOW_POWER)
180 puts (" [low power]");
182 if (f2 & CISTPL_IDE_REG_INHIBIT)
183 puts (" [reg inhibit]");
185 if (f2 & CISTPL_IDE_HAS_INDEX)
188 if (f2 & CISTPL_IDE_IOIS16)
197 static int identify (volatile uchar *p)
199 uchar id_str[MAX_IDENT_CHARS];
206 return (0); /* Don't know */
211 for (i=0; i<=4 && !done; ++i, p+=2) {
212 while ((data = *p) != '\0') {
218 if (t == &id_str[MAX_IDENT_CHARS-1]) {
228 while (--t > id_str) {
234 puts ((char *)id_str);
237 for (card=known_cards; *card; ++card) {
238 debug ("## Compare against \"%s\"\n", *card);
239 if (strcmp((char *)*card, (char *)id_str) == 0) { /* found! */
240 debug ("## CARD FOUND ##\n");
245 return (0); /* don't know */
248 int check_ide_device (int slot)
250 volatile uchar *ident = NULL;
251 volatile uchar *feature_p[MAX_FEATURES];
252 volatile uchar *p, *start, *addr;
256 ushort config_base = 0;
260 addr = (volatile uchar *)(CONFIG_SYS_PCMCIA_MEM_ADDR +
261 CONFIG_SYS_PCMCIA_MEM_SIZE * (slot * 4));
262 debug ("PCMCIA MEM: %08lX\n", (ulong)addr);
264 start = p = (volatile uchar *) addr;
266 while ((p - start) < MAX_TUPEL_SZ) {
270 if (code == 0xFF) { /* End of chain */
275 #if defined(DEBUG) && (DEBUG > 1)
276 { volatile uchar *q = p;
277 printf ("\nTuple code %02x length %d\n\tData:",
280 for (i = 0; i < len; ++i) {
281 printf (" %02x", *q);
291 /* Fix for broken SanDisk which may have 0x80 bit set */
295 if (n_features < MAX_FEATURES)
296 feature_p[n_features++] = p;
299 config_base = (*(p+6) << 8) + (*(p+4));
300 debug ("\n## Config_base = %04x ###\n", config_base);
307 found = identify (ident);
309 if (func_id != ((uchar)~0)) {
310 print_funcid (func_id);
312 if (func_id == CISTPL_FUNCID_FIXED)
315 return (1); /* no disk drive */
318 for (i=0; i<n_features; ++i) {
319 print_fixed (feature_p[i]);
323 printf ("unknown card type\n");
327 ide_devices_found |= (1 << slot);
329 /* set I/O area in config reg -> only valid for ARGOSY D5!!! */
330 *((uchar *)(addr + config_base)) = 1;
332 printf("\n## Config_base = %04x ###\n", config_base);
333 printf("Configuration Option Register: %02x @ %x\n", readb(addr + config_base), addr + config_base);
334 printf("Card Configuration and Status Register: %02x\n", readb(addr + config_base + 2));
335 printf("Pin Replacement Register Register: %02x\n", readb(addr + config_base + 4));
336 printf("Socket and Copy Register: %02x\n", readb(addr + config_base + 6));
341 #endif /* CHECK_IDE_DEVICE */