blob: dfa41e0ae2fdac144bc2f25b6c01f40a77d86c63 [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
Wolfgang Denk67ffef32006-05-12 16:15:46 +02002 * (C) Copyright 2000-2006
wdenkc6097192002-11-03 00:24:07 +00003 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 *
23 ********************************************************************
24 *
25 * Lots of code copied from:
26 *
27 * m8xx_pcmcia.c - Linux PCMCIA socket driver for the mpc8xx series.
28 * (C) 1999-2000 Magnus Damm <damm@bitsmart.com>
29 *
30 * "The ExCA standard specifies that socket controllers should provide
31 * two IO and five memory windows per socket, which can be independently
32 * configured and positioned in the host address space and mapped to
33 * arbitrary segments of card address space. " - David A Hinds. 1999
34 *
35 * This controller does _not_ meet the ExCA standard.
36 *
37 * m8xx pcmcia controller brief info:
38 * + 8 windows (attrib, mem, i/o)
39 * + up to two slots (SLOT_A and SLOT_B)
40 * + inputpins, outputpins, event and mask registers.
41 * - no offset register. sigh.
42 *
43 * Because of the lacking offset register we must map the whole card.
44 * We assign each memory window PCMCIA_MEM_WIN_SIZE address space.
45 * Make sure there is (PCMCIA_MEM_WIN_SIZE * PCMCIA_MEM_WIN_NO
46 * * PCMCIA_SOCKETS_NO) bytes at PCMCIA_MEM_WIN_BASE.
47 * The i/o windows are dynamically allocated at PCMCIA_IO_WIN_BASE.
48 * They are maximum 64KByte each...
49 */
50
51/* #define DEBUG 1 */
52
53/*
54 * PCMCIA support
55 */
56#include <common.h>
57#include <command.h>
58#include <config.h>
59#include <pcmcia.h>
wdenk54070ab2004-12-31 09:32:47 +000060#include <asm/io.h>
61
wdenk90e7e422002-12-04 23:39:58 +000062/* -------------------------------------------------------------------- */
wdenkc6097192002-11-03 00:24:07 +000063
Jon Loeliger3de8b242007-06-11 19:01:54 -050064#if (CONFIG_COMMANDS & CFG_CMD_PCMCIA) || defined(CONFIG_CMD_PCMCIA)
wdenk634d2f72004-04-15 23:14:49 +000065
Wolfgang Denk50440e72006-07-10 23:07:28 +020066extern int pcmcia_on (void);
67extern int pcmcia_off (void);
wdenkc6097192002-11-03 00:24:07 +000068
69int do_pinit (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
70{
71 int rcode = 0;
72
73 if (argc != 2) {
74 printf ("Usage: pinit {on | off}\n");
75 return 1;
76 }
77 if (strcmp(argv[1],"on") == 0) {
Wolfgang Denk50440e72006-07-10 23:07:28 +020078 rcode = pcmcia_on ();
wdenkc6097192002-11-03 00:24:07 +000079 } else if (strcmp(argv[1],"off") == 0) {
80 rcode = pcmcia_off ();
81 } else {
82 printf ("Usage: pinit {on | off}\n");
83 return 1;
84 }
85
86 return rcode;
87}
wdenke5d61c72003-05-18 11:30:09 +000088
Wolfgang Denk50440e72006-07-10 23:07:28 +020089U_BOOT_CMD(
Detlev Zundel409a2852007-05-23 19:02:41 +020090 pinit, 2, 0, do_pinit,
Wolfgang Denk50440e72006-07-10 23:07:28 +020091 "pinit - PCMCIA sub-system\n",
92 "on - power on PCMCIA socket\n"
93 "pinit off - power off PCMCIA socket\n"
94 );
wdenke5d61c72003-05-18 11:30:09 +000095
Wolfgang Denk50440e72006-07-10 23:07:28 +020096#endif /* CONFIG_COMMANDS & CFG_CMD_PCMCIA */
wdenke5d61c72003-05-18 11:30:09 +000097
Wolfgang Denk50440e72006-07-10 23:07:28 +020098/* -------------------------------------------------------------------- */
wdenke5d61c72003-05-18 11:30:09 +000099
Wolfgang Denk50440e72006-07-10 23:07:28 +0200100#undef CHECK_IDE_DEVICE
wdenk634d2f72004-04-15 23:14:49 +0000101
Jon Loeliger3de8b242007-06-11 19:01:54 -0500102#if ((CONFIG_COMMANDS & CFG_CMD_IDE) || defined(CONFIG_CMD_IDE)) \
103 && defined(CONFIG_IDE_8xx_PCCARD)
Wolfgang Denk50440e72006-07-10 23:07:28 +0200104#define CHECK_IDE_DEVICE
wdenk4b6e9052004-02-06 21:48:22 +0000105#endif
Wolfgang Denk50440e72006-07-10 23:07:28 +0200106
107#if defined(CONFIG_PXA_PCMCIA)
108#define CHECK_IDE_DEVICE
wdenkc6097192002-11-03 00:24:07 +0000109#endif
110
Wolfgang Denk50440e72006-07-10 23:07:28 +0200111#ifdef CHECK_IDE_DEVICE
wdenkc6097192002-11-03 00:24:07 +0000112
Wolfgang Denk50440e72006-07-10 23:07:28 +0200113int ide_devices_found;
114static uchar *known_cards[] = {
115 (uchar *)"ARGOSY PnPIDE D5",
116 NULL
117};
wdenkc6097192002-11-03 00:24:07 +0000118
Wolfgang Denk50440e72006-07-10 23:07:28 +0200119#define MAX_TUPEL_SZ 512
120#define MAX_FEATURES 4
wdenkc6097192002-11-03 00:24:07 +0000121
Wolfgang Denk50440e72006-07-10 23:07:28 +0200122#define MAX_IDENT_CHARS 64
123#define MAX_IDENT_FIELDS 4
wdenkc6097192002-11-03 00:24:07 +0000124
Wolfgang Denk50440e72006-07-10 23:07:28 +0200125#define indent "\t "
wdenkc6097192002-11-03 00:24:07 +0000126
Wolfgang Denk50440e72006-07-10 23:07:28 +0200127static void print_funcid (int func)
128{
129 puts (indent);
130 switch (func) {
131 case CISTPL_FUNCID_MULTI:
132 puts (" Multi-Function");
wdenk4b6e9052004-02-06 21:48:22 +0000133 break;
Wolfgang Denk50440e72006-07-10 23:07:28 +0200134 case CISTPL_FUNCID_MEMORY:
135 puts (" Memory");
wdenkc6097192002-11-03 00:24:07 +0000136 break;
Wolfgang Denk50440e72006-07-10 23:07:28 +0200137 case CISTPL_FUNCID_SERIAL:
138 puts (" Serial Port");
wdenkc6097192002-11-03 00:24:07 +0000139 break;
Wolfgang Denk50440e72006-07-10 23:07:28 +0200140 case CISTPL_FUNCID_PARALLEL:
141 puts (" Parallel Port");
wdenkc6097192002-11-03 00:24:07 +0000142 break;
Wolfgang Denk50440e72006-07-10 23:07:28 +0200143 case CISTPL_FUNCID_FIXED:
144 puts (" Fixed Disk");
wdenk67f13362003-12-27 19:24:54 +0000145 break;
Wolfgang Denk50440e72006-07-10 23:07:28 +0200146 case CISTPL_FUNCID_VIDEO:
147 puts (" Video Adapter");
wdenkc6097192002-11-03 00:24:07 +0000148 break;
Wolfgang Denk50440e72006-07-10 23:07:28 +0200149 case CISTPL_FUNCID_NETWORK:
150 puts (" Network Adapter");
151 break;
152 case CISTPL_FUNCID_AIMS:
153 puts (" AIMS Card");
154 break;
155 case CISTPL_FUNCID_SCSI:
156 puts (" SCSI Adapter");
157 break;
158 default:
159 puts (" Unknown");
160 break;
wdenk2029f4d2002-11-21 23:11:29 +0000161 }
Wolfgang Denk50440e72006-07-10 23:07:28 +0200162 puts (" Card\n");
wdenk634d2f72004-04-15 23:14:49 +0000163}
164
Wolfgang Denk50440e72006-07-10 23:07:28 +0200165static void print_fixed (volatile uchar *p)
wdenk634d2f72004-04-15 23:14:49 +0000166{
Wolfgang Denk50440e72006-07-10 23:07:28 +0200167 if (p == NULL)
168 return;
wdenk634d2f72004-04-15 23:14:49 +0000169
Wolfgang Denk50440e72006-07-10 23:07:28 +0200170 puts(indent);
wdenk634d2f72004-04-15 23:14:49 +0000171
Wolfgang Denk50440e72006-07-10 23:07:28 +0200172 switch (*p) {
173 case CISTPL_FUNCE_IDE_IFACE:
174 { uchar iface = *(p+2);
wdenk634d2f72004-04-15 23:14:49 +0000175
Wolfgang Denk50440e72006-07-10 23:07:28 +0200176 puts ((iface == CISTPL_IDE_INTERFACE) ? " IDE" : " unknown");
177 puts (" interface ");
178 break;
179 }
180 case CISTPL_FUNCE_IDE_MASTER:
181 case CISTPL_FUNCE_IDE_SLAVE:
182 { uchar f1 = *(p+2);
183 uchar f2 = *(p+4);
wdenk634d2f72004-04-15 23:14:49 +0000184
Wolfgang Denk50440e72006-07-10 23:07:28 +0200185 puts ((f1 & CISTPL_IDE_SILICON) ? " [silicon]" : " [rotating]");
wdenk634d2f72004-04-15 23:14:49 +0000186
Wolfgang Denk50440e72006-07-10 23:07:28 +0200187 if (f1 & CISTPL_IDE_UNIQUE)
188 puts (" [unique]");
wdenk634d2f72004-04-15 23:14:49 +0000189
Wolfgang Denk50440e72006-07-10 23:07:28 +0200190 puts ((f1 & CISTPL_IDE_DUAL) ? " [dual]" : " [single]");
wdenk634d2f72004-04-15 23:14:49 +0000191
Wolfgang Denk50440e72006-07-10 23:07:28 +0200192 if (f2 & CISTPL_IDE_HAS_SLEEP)
193 puts (" [sleep]");
wdenk634d2f72004-04-15 23:14:49 +0000194
Wolfgang Denk50440e72006-07-10 23:07:28 +0200195 if (f2 & CISTPL_IDE_HAS_STANDBY)
196 puts (" [standby]");
wdenk634d2f72004-04-15 23:14:49 +0000197
Wolfgang Denk50440e72006-07-10 23:07:28 +0200198 if (f2 & CISTPL_IDE_HAS_IDLE)
199 puts (" [idle]");
wdenk634d2f72004-04-15 23:14:49 +0000200
Wolfgang Denk50440e72006-07-10 23:07:28 +0200201 if (f2 & CISTPL_IDE_LOW_POWER)
202 puts (" [low power]");
wdenkc6097192002-11-03 00:24:07 +0000203
Wolfgang Denk50440e72006-07-10 23:07:28 +0200204 if (f2 & CISTPL_IDE_REG_INHIBIT)
205 puts (" [reg inhibit]");
wdenkc6097192002-11-03 00:24:07 +0000206
Wolfgang Denk50440e72006-07-10 23:07:28 +0200207 if (f2 & CISTPL_IDE_HAS_INDEX)
208 puts (" [index]");
wdenke5d61c72003-05-18 11:30:09 +0000209
Wolfgang Denk50440e72006-07-10 23:07:28 +0200210 if (f2 & CISTPL_IDE_IOIS16)
211 puts (" [IOis16]");
wdenke5d61c72003-05-18 11:30:09 +0000212
Wolfgang Denk50440e72006-07-10 23:07:28 +0200213 break;
214 }
215 }
216 putc ('\n');
wdenke5d61c72003-05-18 11:30:09 +0000217}
wdenk634d2f72004-04-15 23:14:49 +0000218
Wolfgang Denk50440e72006-07-10 23:07:28 +0200219static int identify (volatile uchar *p)
wdenkc6097192002-11-03 00:24:07 +0000220{
Wolfgang Denk50440e72006-07-10 23:07:28 +0200221 uchar id_str[MAX_IDENT_CHARS];
222 uchar data;
223 uchar *t;
224 uchar **card;
225 int i, done;
wdenkc6097192002-11-03 00:24:07 +0000226
Wolfgang Denk50440e72006-07-10 23:07:28 +0200227 if (p == NULL)
228 return (0); /* Don't know */
wdenkc6097192002-11-03 00:24:07 +0000229
Wolfgang Denk50440e72006-07-10 23:07:28 +0200230 t = id_str;
231 done =0;
wdenkc6097192002-11-03 00:24:07 +0000232
Wolfgang Denk50440e72006-07-10 23:07:28 +0200233 for (i=0; i<=4 && !done; ++i, p+=2) {
234 while ((data = *p) != '\0') {
235 if (data == 0xFF) {
236 done = 1;
237 break;
238 }
239 *t++ = data;
240 if (t == &id_str[MAX_IDENT_CHARS-1]) {
241 done = 1;
242 break;
243 }
244 p += 2;
245 }
246 if (!done)
247 *t++ = ' ';
wdenkc6097192002-11-03 00:24:07 +0000248 }
Wolfgang Denk50440e72006-07-10 23:07:28 +0200249 *t = '\0';
250 while (--t > id_str) {
251 if (*t == ' ')
252 *t = '\0';
253 else
254 break;
255 }
256 puts ((char *)id_str);
257 putc ('\n');
wdenk634d2f72004-04-15 23:14:49 +0000258
Wolfgang Denk50440e72006-07-10 23:07:28 +0200259 for (card=known_cards; *card; ++card) {
260 debug ("## Compare against \"%s\"\n", *card);
261 if (strcmp((char *)*card, (char *)id_str) == 0) { /* found! */
262 debug ("## CARD FOUND ##\n");
263 return (1);
264 }
265 }
wdenkc6097192002-11-03 00:24:07 +0000266
Wolfgang Denk50440e72006-07-10 23:07:28 +0200267 return (0); /* don't know */
wdenk634d2f72004-04-15 23:14:49 +0000268}
wdenkc6097192002-11-03 00:24:07 +0000269
Wolfgang Denk50440e72006-07-10 23:07:28 +0200270int check_ide_device (int slot)
wdenkc6097192002-11-03 00:24:07 +0000271{
272 volatile uchar *ident = NULL;
273 volatile uchar *feature_p[MAX_FEATURES];
wdenk2029f4d2002-11-21 23:11:29 +0000274 volatile uchar *p, *start, *addr;
wdenkc6097192002-11-03 00:24:07 +0000275 int n_features = 0;
276 uchar func_id = ~0;
277 uchar code, len;
278 ushort config_base = 0;
279 int found = 0;
280 int i;
281
wdenk90e7e422002-12-04 23:39:58 +0000282 addr = (volatile uchar *)(CFG_PCMCIA_MEM_ADDR +
283 CFG_PCMCIA_MEM_SIZE * (slot * 4));
wdenke7f34c62003-01-11 09:48:40 +0000284 debug ("PCMCIA MEM: %08lX\n", (ulong)addr);
wdenkc6097192002-11-03 00:24:07 +0000285
wdenk2029f4d2002-11-21 23:11:29 +0000286 start = p = (volatile uchar *) addr;
wdenkc6097192002-11-03 00:24:07 +0000287
288 while ((p - start) < MAX_TUPEL_SZ) {
289
290 code = *p; p += 2;
291
292 if (code == 0xFF) { /* End of chain */
293 break;
294 }
295
296 len = *p; p += 2;
297#if defined(DEBUG) && (DEBUG > 1)
298 { volatile uchar *q = p;
299 printf ("\nTuple code %02x length %d\n\tData:",
300 code, len);
301
302 for (i = 0; i < len; ++i) {
303 printf (" %02x", *q);
304 q+= 2;
305 }
306 }
307#endif /* DEBUG */
308 switch (code) {
309 case CISTPL_VERS_1:
310 ident = p + 4;
311 break;
312 case CISTPL_FUNCID:
313 /* Fix for broken SanDisk which may have 0x80 bit set */
314 func_id = *p & 0x7F;
315 break;
316 case CISTPL_FUNCE:
317 if (n_features < MAX_FEATURES)
318 feature_p[n_features++] = p;
319 break;
320 case CISTPL_CONFIG:
321 config_base = (*(p+6) << 8) + (*(p+4));
322 debug ("\n## Config_base = %04x ###\n", config_base);
323 default:
324 break;
325 }
326 p += 2 * len;
327 }
328
329 found = identify (ident);
330
331 if (func_id != ((uchar)~0)) {
332 print_funcid (func_id);
333
334 if (func_id == CISTPL_FUNCID_FIXED)
335 found = 1;
336 else
337 return (1); /* no disk drive */
338 }
339
340 for (i=0; i<n_features; ++i) {
341 print_fixed (feature_p[i]);
342 }
343
344 if (!found) {
345 printf ("unknown card type\n");
346 return (1);
347 }
348
wdenk4fc95692003-02-28 00:49:47 +0000349 ide_devices_found |= (1 << slot);
350
wdenk54070ab2004-12-31 09:32:47 +0000351#if CONFIG_CPC45
352#else
wdenkc6097192002-11-03 00:24:07 +0000353 /* set I/O area in config reg -> only valid for ARGOSY D5!!! */
wdenk2029f4d2002-11-21 23:11:29 +0000354 *((uchar *)(addr + config_base)) = 1;
wdenk54070ab2004-12-31 09:32:47 +0000355#endif
356#if 0
357 printf("\n## Config_base = %04x ###\n", config_base);
358 printf("Configuration Option Register: %02x @ %x\n", readb(addr + config_base), addr + config_base);
359 printf("Card Configuration and Status Register: %02x\n", readb(addr + config_base + 2));
360 printf("Pin Replacement Register Register: %02x\n", readb(addr + config_base + 4));
361 printf("Socket and Copy Register: %02x\n", readb(addr + config_base + 6));
362#endif
wdenkc6097192002-11-03 00:24:07 +0000363 return (0);
364}
wdenkc6097192002-11-03 00:24:07 +0000365
Wolfgang Denk50440e72006-07-10 23:07:28 +0200366#endif /* CHECK_IDE_DEVICE */