cmd_pcmcia.c 7.9 KB

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