1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
22e192b24SSimon Glass /*
32e192b24SSimon Glass * (C) Copyright 2000-2006
42e192b24SSimon Glass * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
52e192b24SSimon Glass *
62e192b24SSimon Glass ********************************************************************
72e192b24SSimon Glass *
82e192b24SSimon Glass * Lots of code copied from:
92e192b24SSimon Glass *
102e192b24SSimon Glass * m8xx_pcmcia.c - Linux PCMCIA socket driver for the mpc8xx series.
112e192b24SSimon Glass * (C) 1999-2000 Magnus Damm <damm@bitsmart.com>
122e192b24SSimon Glass *
132e192b24SSimon Glass * "The ExCA standard specifies that socket controllers should provide
142e192b24SSimon Glass * two IO and five memory windows per socket, which can be independently
152e192b24SSimon Glass * configured and positioned in the host address space and mapped to
162e192b24SSimon Glass * arbitrary segments of card address space. " - David A Hinds. 1999
172e192b24SSimon Glass *
182e192b24SSimon Glass * This controller does _not_ meet the ExCA standard.
192e192b24SSimon Glass *
202e192b24SSimon Glass * m8xx pcmcia controller brief info:
212e192b24SSimon Glass * + 8 windows (attrib, mem, i/o)
222e192b24SSimon Glass * + up to two slots (SLOT_A and SLOT_B)
232e192b24SSimon Glass * + inputpins, outputpins, event and mask registers.
242e192b24SSimon Glass * - no offset register. sigh.
252e192b24SSimon Glass *
262e192b24SSimon Glass * Because of the lacking offset register we must map the whole card.
272e192b24SSimon Glass * We assign each memory window PCMCIA_MEM_WIN_SIZE address space.
282e192b24SSimon Glass * Make sure there is (PCMCIA_MEM_WIN_SIZE * PCMCIA_MEM_WIN_NO
292e192b24SSimon Glass * * PCMCIA_SOCKETS_NO) bytes at PCMCIA_MEM_WIN_BASE.
302e192b24SSimon Glass * The i/o windows are dynamically allocated at PCMCIA_IO_WIN_BASE.
312e192b24SSimon Glass * They are maximum 64KByte each...
322e192b24SSimon Glass */
332e192b24SSimon Glass
342e192b24SSimon Glass /* #define DEBUG 1 */
352e192b24SSimon Glass
362e192b24SSimon Glass /*
372e192b24SSimon Glass * PCMCIA support
382e192b24SSimon Glass */
392e192b24SSimon Glass #include <common.h>
402e192b24SSimon Glass #include <command.h>
412e192b24SSimon Glass #include <config.h>
422e192b24SSimon Glass #include <pcmcia.h>
432e192b24SSimon Glass #include <asm/io.h>
442e192b24SSimon Glass
452e192b24SSimon Glass /* -------------------------------------------------------------------- */
462e192b24SSimon Glass
472e192b24SSimon Glass #if defined(CONFIG_CMD_PCMCIA)
482e192b24SSimon Glass
492e192b24SSimon Glass extern int pcmcia_on (void);
502e192b24SSimon Glass extern int pcmcia_off (void);
512e192b24SSimon Glass
do_pinit(cmd_tbl_t * cmdtp,int flag,int argc,char * const argv[])522e192b24SSimon Glass int do_pinit (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
532e192b24SSimon Glass {
542e192b24SSimon Glass int rcode = 0;
552e192b24SSimon Glass
562e192b24SSimon Glass if (argc != 2) {
572e192b24SSimon Glass printf ("Usage: pinit {on | off}\n");
582e192b24SSimon Glass return 1;
592e192b24SSimon Glass }
602e192b24SSimon Glass if (strcmp(argv[1],"on") == 0) {
612e192b24SSimon Glass rcode = pcmcia_on ();
622e192b24SSimon Glass } else if (strcmp(argv[1],"off") == 0) {
632e192b24SSimon Glass rcode = pcmcia_off ();
642e192b24SSimon Glass } else {
652e192b24SSimon Glass printf ("Usage: pinit {on | off}\n");
662e192b24SSimon Glass return 1;
672e192b24SSimon Glass }
682e192b24SSimon Glass
692e192b24SSimon Glass return rcode;
702e192b24SSimon Glass }
712e192b24SSimon Glass
722e192b24SSimon Glass U_BOOT_CMD(
732e192b24SSimon Glass pinit, 2, 0, do_pinit,
742e192b24SSimon Glass "PCMCIA sub-system",
752e192b24SSimon Glass "on - power on PCMCIA socket\n"
762e192b24SSimon Glass "pinit off - power off PCMCIA socket"
772e192b24SSimon Glass );
782e192b24SSimon Glass
792e192b24SSimon Glass #endif
802e192b24SSimon Glass
812e192b24SSimon Glass /* -------------------------------------------------------------------- */
822e192b24SSimon Glass
832e192b24SSimon Glass #undef CHECK_IDE_DEVICE
842e192b24SSimon Glass
852e192b24SSimon Glass #if defined(CONFIG_PXA_PCMCIA)
862e192b24SSimon Glass #define CHECK_IDE_DEVICE
872e192b24SSimon Glass #endif
882e192b24SSimon Glass
892e192b24SSimon Glass #ifdef CHECK_IDE_DEVICE
902e192b24SSimon Glass
912e192b24SSimon Glass int ide_devices_found;
922e192b24SSimon Glass static uchar *known_cards[] = {
932e192b24SSimon Glass (uchar *)"ARGOSY PnPIDE D5",
942e192b24SSimon Glass NULL
952e192b24SSimon Glass };
962e192b24SSimon Glass
972e192b24SSimon Glass #define MAX_TUPEL_SZ 512
982e192b24SSimon Glass #define MAX_FEATURES 4
992e192b24SSimon Glass
1002e192b24SSimon Glass #define MAX_IDENT_CHARS 64
1012e192b24SSimon Glass #define MAX_IDENT_FIELDS 4
1022e192b24SSimon Glass
1032e192b24SSimon Glass #define indent "\t "
1042e192b24SSimon Glass
print_funcid(int func)1052e192b24SSimon Glass static void print_funcid (int func)
1062e192b24SSimon Glass {
1072e192b24SSimon Glass puts (indent);
1082e192b24SSimon Glass switch (func) {
1092e192b24SSimon Glass case CISTPL_FUNCID_MULTI:
1102e192b24SSimon Glass puts (" Multi-Function");
1112e192b24SSimon Glass break;
1122e192b24SSimon Glass case CISTPL_FUNCID_MEMORY:
1132e192b24SSimon Glass puts (" Memory");
1142e192b24SSimon Glass break;
1152e192b24SSimon Glass case CISTPL_FUNCID_SERIAL:
1162e192b24SSimon Glass puts (" Serial Port");
1172e192b24SSimon Glass break;
1182e192b24SSimon Glass case CISTPL_FUNCID_PARALLEL:
1192e192b24SSimon Glass puts (" Parallel Port");
1202e192b24SSimon Glass break;
1212e192b24SSimon Glass case CISTPL_FUNCID_FIXED:
1222e192b24SSimon Glass puts (" Fixed Disk");
1232e192b24SSimon Glass break;
1242e192b24SSimon Glass case CISTPL_FUNCID_VIDEO:
1252e192b24SSimon Glass puts (" Video Adapter");
1262e192b24SSimon Glass break;
1272e192b24SSimon Glass case CISTPL_FUNCID_NETWORK:
1282e192b24SSimon Glass puts (" Network Adapter");
1292e192b24SSimon Glass break;
1302e192b24SSimon Glass case CISTPL_FUNCID_AIMS:
1312e192b24SSimon Glass puts (" AIMS Card");
1322e192b24SSimon Glass break;
1332e192b24SSimon Glass case CISTPL_FUNCID_SCSI:
1342e192b24SSimon Glass puts (" SCSI Adapter");
1352e192b24SSimon Glass break;
1362e192b24SSimon Glass default:
1372e192b24SSimon Glass puts (" Unknown");
1382e192b24SSimon Glass break;
1392e192b24SSimon Glass }
1402e192b24SSimon Glass puts (" Card\n");
1412e192b24SSimon Glass }
1422e192b24SSimon Glass
print_fixed(volatile uchar * p)1432e192b24SSimon Glass static void print_fixed (volatile uchar *p)
1442e192b24SSimon Glass {
1452e192b24SSimon Glass if (p == NULL)
1462e192b24SSimon Glass return;
1472e192b24SSimon Glass
1482e192b24SSimon Glass puts(indent);
1492e192b24SSimon Glass
1502e192b24SSimon Glass switch (*p) {
1512e192b24SSimon Glass case CISTPL_FUNCE_IDE_IFACE:
1522e192b24SSimon Glass { uchar iface = *(p+2);
1532e192b24SSimon Glass
1542e192b24SSimon Glass puts ((iface == CISTPL_IDE_INTERFACE) ? " IDE" : " unknown");
1552e192b24SSimon Glass puts (" interface ");
1562e192b24SSimon Glass break;
1572e192b24SSimon Glass }
1582e192b24SSimon Glass case CISTPL_FUNCE_IDE_MASTER:
1592e192b24SSimon Glass case CISTPL_FUNCE_IDE_SLAVE:
1602e192b24SSimon Glass { uchar f1 = *(p+2);
1612e192b24SSimon Glass uchar f2 = *(p+4);
1622e192b24SSimon Glass
1632e192b24SSimon Glass puts ((f1 & CISTPL_IDE_SILICON) ? " [silicon]" : " [rotating]");
1642e192b24SSimon Glass
1652e192b24SSimon Glass if (f1 & CISTPL_IDE_UNIQUE)
1662e192b24SSimon Glass puts (" [unique]");
1672e192b24SSimon Glass
1682e192b24SSimon Glass puts ((f1 & CISTPL_IDE_DUAL) ? " [dual]" : " [single]");
1692e192b24SSimon Glass
1702e192b24SSimon Glass if (f2 & CISTPL_IDE_HAS_SLEEP)
1712e192b24SSimon Glass puts (" [sleep]");
1722e192b24SSimon Glass
1732e192b24SSimon Glass if (f2 & CISTPL_IDE_HAS_STANDBY)
1742e192b24SSimon Glass puts (" [standby]");
1752e192b24SSimon Glass
1762e192b24SSimon Glass if (f2 & CISTPL_IDE_HAS_IDLE)
1772e192b24SSimon Glass puts (" [idle]");
1782e192b24SSimon Glass
1792e192b24SSimon Glass if (f2 & CISTPL_IDE_LOW_POWER)
1802e192b24SSimon Glass puts (" [low power]");
1812e192b24SSimon Glass
1822e192b24SSimon Glass if (f2 & CISTPL_IDE_REG_INHIBIT)
1832e192b24SSimon Glass puts (" [reg inhibit]");
1842e192b24SSimon Glass
1852e192b24SSimon Glass if (f2 & CISTPL_IDE_HAS_INDEX)
1862e192b24SSimon Glass puts (" [index]");
1872e192b24SSimon Glass
1882e192b24SSimon Glass if (f2 & CISTPL_IDE_IOIS16)
1892e192b24SSimon Glass puts (" [IOis16]");
1902e192b24SSimon Glass
1912e192b24SSimon Glass break;
1922e192b24SSimon Glass }
1932e192b24SSimon Glass }
1942e192b24SSimon Glass putc ('\n');
1952e192b24SSimon Glass }
1962e192b24SSimon Glass
identify(volatile uchar * p)1972e192b24SSimon Glass static int identify (volatile uchar *p)
1982e192b24SSimon Glass {
1992e192b24SSimon Glass uchar id_str[MAX_IDENT_CHARS];
2002e192b24SSimon Glass uchar data;
2012e192b24SSimon Glass uchar *t;
2022e192b24SSimon Glass uchar **card;
2032e192b24SSimon Glass int i, done;
2042e192b24SSimon Glass
2052e192b24SSimon Glass if (p == NULL)
2062e192b24SSimon Glass return (0); /* Don't know */
2072e192b24SSimon Glass
2082e192b24SSimon Glass t = id_str;
2092e192b24SSimon Glass done =0;
2102e192b24SSimon Glass
2112e192b24SSimon Glass for (i=0; i<=4 && !done; ++i, p+=2) {
2122e192b24SSimon Glass while ((data = *p) != '\0') {
2132e192b24SSimon Glass if (data == 0xFF) {
2142e192b24SSimon Glass done = 1;
2152e192b24SSimon Glass break;
2162e192b24SSimon Glass }
2172e192b24SSimon Glass *t++ = data;
2182e192b24SSimon Glass if (t == &id_str[MAX_IDENT_CHARS-1]) {
2192e192b24SSimon Glass done = 1;
2202e192b24SSimon Glass break;
2212e192b24SSimon Glass }
2222e192b24SSimon Glass p += 2;
2232e192b24SSimon Glass }
2242e192b24SSimon Glass if (!done)
2252e192b24SSimon Glass *t++ = ' ';
2262e192b24SSimon Glass }
2272e192b24SSimon Glass *t = '\0';
2282e192b24SSimon Glass while (--t > id_str) {
2292e192b24SSimon Glass if (*t == ' ')
2302e192b24SSimon Glass *t = '\0';
2312e192b24SSimon Glass else
2322e192b24SSimon Glass break;
2332e192b24SSimon Glass }
2342e192b24SSimon Glass puts ((char *)id_str);
2352e192b24SSimon Glass putc ('\n');
2362e192b24SSimon Glass
2372e192b24SSimon Glass for (card=known_cards; *card; ++card) {
2382e192b24SSimon Glass debug ("## Compare against \"%s\"\n", *card);
2392e192b24SSimon Glass if (strcmp((char *)*card, (char *)id_str) == 0) { /* found! */
2402e192b24SSimon Glass debug ("## CARD FOUND ##\n");
2412e192b24SSimon Glass return (1);
2422e192b24SSimon Glass }
2432e192b24SSimon Glass }
2442e192b24SSimon Glass
2452e192b24SSimon Glass return (0); /* don't know */
2462e192b24SSimon Glass }
2472e192b24SSimon Glass
check_ide_device(int slot)2482e192b24SSimon Glass int check_ide_device (int slot)
2492e192b24SSimon Glass {
2502e192b24SSimon Glass volatile uchar *ident = NULL;
2512e192b24SSimon Glass volatile uchar *feature_p[MAX_FEATURES];
2522e192b24SSimon Glass volatile uchar *p, *start, *addr;
2532e192b24SSimon Glass int n_features = 0;
2542e192b24SSimon Glass uchar func_id = ~0;
2552e192b24SSimon Glass uchar code, len;
2562e192b24SSimon Glass ushort config_base = 0;
2572e192b24SSimon Glass int found = 0;
2582e192b24SSimon Glass int i;
2592e192b24SSimon Glass
2602e192b24SSimon Glass addr = (volatile uchar *)(CONFIG_SYS_PCMCIA_MEM_ADDR +
2612e192b24SSimon Glass CONFIG_SYS_PCMCIA_MEM_SIZE * (slot * 4));
2622e192b24SSimon Glass debug ("PCMCIA MEM: %08lX\n", (ulong)addr);
2632e192b24SSimon Glass
2642e192b24SSimon Glass start = p = (volatile uchar *) addr;
2652e192b24SSimon Glass
2662e192b24SSimon Glass while ((p - start) < MAX_TUPEL_SZ) {
2672e192b24SSimon Glass
2682e192b24SSimon Glass code = *p; p += 2;
2692e192b24SSimon Glass
2702e192b24SSimon Glass if (code == 0xFF) { /* End of chain */
2712e192b24SSimon Glass break;
2722e192b24SSimon Glass }
2732e192b24SSimon Glass
2742e192b24SSimon Glass len = *p; p += 2;
2752e192b24SSimon Glass #if defined(DEBUG) && (DEBUG > 1)
2762e192b24SSimon Glass { volatile uchar *q = p;
2772e192b24SSimon Glass printf ("\nTuple code %02x length %d\n\tData:",
2782e192b24SSimon Glass code, len);
2792e192b24SSimon Glass
2802e192b24SSimon Glass for (i = 0; i < len; ++i) {
2812e192b24SSimon Glass printf (" %02x", *q);
2822e192b24SSimon Glass q+= 2;
2832e192b24SSimon Glass }
2842e192b24SSimon Glass }
2852e192b24SSimon Glass #endif /* DEBUG */
2862e192b24SSimon Glass switch (code) {
2872e192b24SSimon Glass case CISTPL_VERS_1:
2882e192b24SSimon Glass ident = p + 4;
2892e192b24SSimon Glass break;
2902e192b24SSimon Glass case CISTPL_FUNCID:
2912e192b24SSimon Glass /* Fix for broken SanDisk which may have 0x80 bit set */
2922e192b24SSimon Glass func_id = *p & 0x7F;
2932e192b24SSimon Glass break;
2942e192b24SSimon Glass case CISTPL_FUNCE:
2952e192b24SSimon Glass if (n_features < MAX_FEATURES)
2962e192b24SSimon Glass feature_p[n_features++] = p;
2972e192b24SSimon Glass break;
2982e192b24SSimon Glass case CISTPL_CONFIG:
2992e192b24SSimon Glass config_base = (*(p+6) << 8) + (*(p+4));
3002e192b24SSimon Glass debug ("\n## Config_base = %04x ###\n", config_base);
3012e192b24SSimon Glass default:
3022e192b24SSimon Glass break;
3032e192b24SSimon Glass }
3042e192b24SSimon Glass p += 2 * len;
3052e192b24SSimon Glass }
3062e192b24SSimon Glass
3072e192b24SSimon Glass found = identify (ident);
3082e192b24SSimon Glass
3092e192b24SSimon Glass if (func_id != ((uchar)~0)) {
3102e192b24SSimon Glass print_funcid (func_id);
3112e192b24SSimon Glass
3122e192b24SSimon Glass if (func_id == CISTPL_FUNCID_FIXED)
3132e192b24SSimon Glass found = 1;
3142e192b24SSimon Glass else
3152e192b24SSimon Glass return (1); /* no disk drive */
3162e192b24SSimon Glass }
3172e192b24SSimon Glass
3182e192b24SSimon Glass for (i=0; i<n_features; ++i) {
3192e192b24SSimon Glass print_fixed (feature_p[i]);
3202e192b24SSimon Glass }
3212e192b24SSimon Glass
3222e192b24SSimon Glass if (!found) {
3232e192b24SSimon Glass printf ("unknown card type\n");
3242e192b24SSimon Glass return (1);
3252e192b24SSimon Glass }
3262e192b24SSimon Glass
3272e192b24SSimon Glass ide_devices_found |= (1 << slot);
3282e192b24SSimon Glass
3292e192b24SSimon Glass /* set I/O area in config reg -> only valid for ARGOSY D5!!! */
3302e192b24SSimon Glass *((uchar *)(addr + config_base)) = 1;
3312e192b24SSimon Glass #if 0
3322e192b24SSimon Glass printf("\n## Config_base = %04x ###\n", config_base);
3332e192b24SSimon Glass printf("Configuration Option Register: %02x @ %x\n", readb(addr + config_base), addr + config_base);
3342e192b24SSimon Glass printf("Card Configuration and Status Register: %02x\n", readb(addr + config_base + 2));
3352e192b24SSimon Glass printf("Pin Replacement Register Register: %02x\n", readb(addr + config_base + 4));
3362e192b24SSimon Glass printf("Socket and Copy Register: %02x\n", readb(addr + config_base + 6));
3372e192b24SSimon Glass #endif
3382e192b24SSimon Glass return (0);
3392e192b24SSimon Glass }
3402e192b24SSimon Glass
3412e192b24SSimon Glass #endif /* CHECK_IDE_DEVICE */
342