cmd_pcmcia.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. /*
  2. * (C) Copyright 2000-2006
  3. * 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. /* #define DEBUG 1 */
  51. /*
  52. * PCMCIA support
  53. */
  54. #include <common.h>
  55. #include <command.h>
  56. #include <config.h>
  57. #include <pcmcia.h>
  58. #include <asm/io.h>
  59. /* -------------------------------------------------------------------- */
  60. #if (CONFIG_COMMANDS & CFG_CMD_PCMCIA) || defined(CONFIG_CMD_PCMCIA)
  61. extern int pcmcia_on (void);
  62. extern int pcmcia_off (void);
  63. int do_pinit (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  64. {
  65. int rcode = 0;
  66. if (argc != 2) {
  67. printf ("Usage: pinit {on | off}\n");
  68. return 1;
  69. }
  70. if (strcmp(argv[1],"on") == 0) {
  71. rcode = pcmcia_on ();
  72. } else if (strcmp(argv[1],"off") == 0) {
  73. rcode = pcmcia_off ();
  74. } else {
  75. printf ("Usage: pinit {on | off}\n");
  76. return 1;
  77. }
  78. return rcode;
  79. }
  80. U_BOOT_CMD(
  81. pinit, 2, 0, do_pinit,
  82. "pinit - PCMCIA sub-system\n",
  83. "on - power on PCMCIA socket\n"
  84. "pinit off - power off PCMCIA socket\n"
  85. );
  86. #endif /* CONFIG_COMMANDS & CFG_CMD_PCMCIA */
  87. /* -------------------------------------------------------------------- */
  88. #undef CHECK_IDE_DEVICE
  89. #if ((CONFIG_COMMANDS & CFG_CMD_IDE) || defined(CONFIG_CMD_IDE)) \
  90. && defined(CONFIG_IDE_8xx_PCCARD)
  91. #define CHECK_IDE_DEVICE
  92. #endif
  93. #if defined(CONFIG_PXA_PCMCIA)
  94. #define CHECK_IDE_DEVICE
  95. #endif
  96. #ifdef CHECK_IDE_DEVICE
  97. int ide_devices_found;
  98. static uchar *known_cards[] = {
  99. (uchar *)"ARGOSY PnPIDE D5",
  100. NULL
  101. };
  102. #define MAX_TUPEL_SZ 512
  103. #define MAX_FEATURES 4
  104. #define MAX_IDENT_CHARS 64
  105. #define MAX_IDENT_FIELDS 4
  106. #define indent "\t "
  107. static void print_funcid (int func)
  108. {
  109. puts (indent);
  110. switch (func) {
  111. case CISTPL_FUNCID_MULTI:
  112. puts (" Multi-Function");
  113. break;
  114. case CISTPL_FUNCID_MEMORY:
  115. puts (" Memory");
  116. break;
  117. case CISTPL_FUNCID_SERIAL:
  118. puts (" Serial Port");
  119. break;
  120. case CISTPL_FUNCID_PARALLEL:
  121. puts (" Parallel Port");
  122. break;
  123. case CISTPL_FUNCID_FIXED:
  124. puts (" Fixed Disk");
  125. break;
  126. case CISTPL_FUNCID_VIDEO:
  127. puts (" Video Adapter");
  128. break;
  129. case CISTPL_FUNCID_NETWORK:
  130. puts (" Network Adapter");
  131. break;
  132. case CISTPL_FUNCID_AIMS:
  133. puts (" AIMS Card");
  134. break;
  135. case CISTPL_FUNCID_SCSI:
  136. puts (" SCSI Adapter");
  137. break;
  138. default:
  139. puts (" Unknown");
  140. break;
  141. }
  142. puts (" Card\n");
  143. }
  144. static void print_fixed (volatile uchar *p)
  145. {
  146. if (p == NULL)
  147. return;
  148. puts(indent);
  149. switch (*p) {
  150. case CISTPL_FUNCE_IDE_IFACE:
  151. { uchar iface = *(p+2);
  152. puts ((iface == CISTPL_IDE_INTERFACE) ? " IDE" : " unknown");
  153. puts (" interface ");
  154. break;
  155. }
  156. case CISTPL_FUNCE_IDE_MASTER:
  157. case CISTPL_FUNCE_IDE_SLAVE:
  158. { uchar f1 = *(p+2);
  159. uchar f2 = *(p+4);
  160. puts ((f1 & CISTPL_IDE_SILICON) ? " [silicon]" : " [rotating]");
  161. if (f1 & CISTPL_IDE_UNIQUE)
  162. puts (" [unique]");
  163. puts ((f1 & CISTPL_IDE_DUAL) ? " [dual]" : " [single]");
  164. if (f2 & CISTPL_IDE_HAS_SLEEP)
  165. puts (" [sleep]");
  166. if (f2 & CISTPL_IDE_HAS_STANDBY)
  167. puts (" [standby]");
  168. if (f2 & CISTPL_IDE_HAS_IDLE)
  169. puts (" [idle]");
  170. if (f2 & CISTPL_IDE_LOW_POWER)
  171. puts (" [low power]");
  172. if (f2 & CISTPL_IDE_REG_INHIBIT)
  173. puts (" [reg inhibit]");
  174. if (f2 & CISTPL_IDE_HAS_INDEX)
  175. puts (" [index]");
  176. if (f2 & CISTPL_IDE_IOIS16)
  177. puts (" [IOis16]");
  178. break;
  179. }
  180. }
  181. putc ('\n');
  182. }
  183. static int identify (volatile uchar *p)
  184. {
  185. uchar id_str[MAX_IDENT_CHARS];
  186. uchar data;
  187. uchar *t;
  188. uchar **card;
  189. int i, done;
  190. if (p == NULL)
  191. return (0); /* Don't know */
  192. t = id_str;
  193. done =0;
  194. for (i=0; i<=4 && !done; ++i, p+=2) {
  195. while ((data = *p) != '\0') {
  196. if (data == 0xFF) {
  197. done = 1;
  198. break;
  199. }
  200. *t++ = data;
  201. if (t == &id_str[MAX_IDENT_CHARS-1]) {
  202. done = 1;
  203. break;
  204. }
  205. p += 2;
  206. }
  207. if (!done)
  208. *t++ = ' ';
  209. }
  210. *t = '\0';
  211. while (--t > id_str) {
  212. if (*t == ' ')
  213. *t = '\0';
  214. else
  215. break;
  216. }
  217. puts ((char *)id_str);
  218. putc ('\n');
  219. for (card=known_cards; *card; ++card) {
  220. debug ("## Compare against \"%s\"\n", *card);
  221. if (strcmp((char *)*card, (char *)id_str) == 0) { /* found! */
  222. debug ("## CARD FOUND ##\n");
  223. return (1);
  224. }
  225. }
  226. return (0); /* don't know */
  227. }
  228. int check_ide_device (int slot)
  229. {
  230. volatile uchar *ident = NULL;
  231. volatile uchar *feature_p[MAX_FEATURES];
  232. volatile uchar *p, *start, *addr;
  233. int n_features = 0;
  234. uchar func_id = ~0;
  235. uchar code, len;
  236. ushort config_base = 0;
  237. int found = 0;
  238. int i;
  239. addr = (volatile uchar *)(CFG_PCMCIA_MEM_ADDR +
  240. CFG_PCMCIA_MEM_SIZE * (slot * 4));
  241. debug ("PCMCIA MEM: %08lX\n", (ulong)addr);
  242. start = p = (volatile uchar *) addr;
  243. while ((p - start) < MAX_TUPEL_SZ) {
  244. code = *p; p += 2;
  245. if (code == 0xFF) { /* End of chain */
  246. break;
  247. }
  248. len = *p; p += 2;
  249. #if defined(DEBUG) && (DEBUG > 1)
  250. { volatile uchar *q = p;
  251. printf ("\nTuple code %02x length %d\n\tData:",
  252. code, len);
  253. for (i = 0; i < len; ++i) {
  254. printf (" %02x", *q);
  255. q+= 2;
  256. }
  257. }
  258. #endif /* DEBUG */
  259. switch (code) {
  260. case CISTPL_VERS_1:
  261. ident = p + 4;
  262. break;
  263. case CISTPL_FUNCID:
  264. /* Fix for broken SanDisk which may have 0x80 bit set */
  265. func_id = *p & 0x7F;
  266. break;
  267. case CISTPL_FUNCE:
  268. if (n_features < MAX_FEATURES)
  269. feature_p[n_features++] = p;
  270. break;
  271. case CISTPL_CONFIG:
  272. config_base = (*(p+6) << 8) + (*(p+4));
  273. debug ("\n## Config_base = %04x ###\n", config_base);
  274. default:
  275. break;
  276. }
  277. p += 2 * len;
  278. }
  279. found = identify (ident);
  280. if (func_id != ((uchar)~0)) {
  281. print_funcid (func_id);
  282. if (func_id == CISTPL_FUNCID_FIXED)
  283. found = 1;
  284. else
  285. return (1); /* no disk drive */
  286. }
  287. for (i=0; i<n_features; ++i) {
  288. print_fixed (feature_p[i]);
  289. }
  290. if (!found) {
  291. printf ("unknown card type\n");
  292. return (1);
  293. }
  294. ide_devices_found |= (1 << slot);
  295. #if CONFIG_CPC45
  296. #else
  297. /* set I/O area in config reg -> only valid for ARGOSY D5!!! */
  298. *((uchar *)(addr + config_base)) = 1;
  299. #endif
  300. #if 0
  301. printf("\n## Config_base = %04x ###\n", config_base);
  302. printf("Configuration Option Register: %02x @ %x\n", readb(addr + config_base), addr + config_base);
  303. printf("Card Configuration and Status Register: %02x\n", readb(addr + config_base + 2));
  304. printf("Pin Replacement Register Register: %02x\n", readb(addr + config_base + 4));
  305. printf("Socket and Copy Register: %02x\n", readb(addr + config_base + 6));
  306. #endif
  307. return (0);
  308. }
  309. #endif /* CHECK_IDE_DEVICE */