ti_pci1410a.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. /*
  2. * (C) Copyright 2000-2002
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. * (C) Copyright 2002
  5. * Daniel Engström, Omicron Ceti AB
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. *
  9. ********************************************************************
  10. *
  11. * Lots of code copied from:
  12. *
  13. * m8xx_pcmcia.c - Linux PCMCIA socket driver for the mpc8xx series.
  14. * (C) 1999-2000 Magnus Damm <damm@bitsmart.com>
  15. *
  16. * "The ExCA standard specifies that socket controllers should provide
  17. * two IO and five memory windows per socket, which can be independently
  18. * configured and positioned in the host address space and mapped to
  19. * arbitrary segments of card address space. " - David A Hinds. 1999
  20. *
  21. * This controller does _not_ meet the ExCA standard.
  22. *
  23. * m8xx pcmcia controller brief info:
  24. * + 8 windows (attrib, mem, i/o)
  25. * + up to two slots (SLOT_A and SLOT_B)
  26. * + inputpins, outputpins, event and mask registers.
  27. * - no offset register. sigh.
  28. *
  29. * Because of the lacking offset register we must map the whole card.
  30. * We assign each memory window PCMCIA_MEM_WIN_SIZE address space.
  31. * Make sure there is (PCMCIA_MEM_WIN_SIZE * PCMCIA_MEM_WIN_NO
  32. * * PCMCIA_SOCKETS_NO) bytes at PCMCIA_MEM_WIN_BASE.
  33. * The i/o windows are dynamically allocated at PCMCIA_IO_WIN_BASE.
  34. * They are maximum 64KByte each...
  35. */
  36. #undef DEBUG /**/
  37. /*
  38. * PCMCIA support
  39. */
  40. #include <common.h>
  41. #include <command.h>
  42. #include <config.h>
  43. #include <pci.h>
  44. #include <asm/io.h>
  45. #include <pcmcia.h>
  46. #if defined(CONFIG_CMD_PCMCIA)
  47. int pcmcia_on(int ide_base_bus);
  48. static int hardware_disable(int slot);
  49. static int hardware_enable(int slot);
  50. static int voltage_set(int slot, int vcc, int vpp);
  51. static void print_funcid(int func);
  52. static void print_fixed(volatile char *p);
  53. static int identify(volatile char *p);
  54. static int check_ide_device(int slot, int ide_base_bus);
  55. /* ------------------------------------------------------------------------- */
  56. const char *indent = "\t ";
  57. /* ------------------------------------------------------------------------- */
  58. static struct pci_device_id supported[] = {
  59. { PCI_VENDOR_ID_TI, 0xac50 }, /* Ti PCI1410A */
  60. { PCI_VENDOR_ID_TI, 0xac56 }, /* Ti PCI1510 */
  61. { }
  62. };
  63. static pci_dev_t devbusfn;
  64. static u32 socket_base;
  65. static u32 pcmcia_cis_ptr;
  66. int pcmcia_on(int ide_base_bus)
  67. {
  68. u16 dev_id;
  69. u32 socket_status;
  70. int slot = 0;
  71. int cis_len;
  72. u16 io_base;
  73. u16 io_len;
  74. /*
  75. * Find the CardBus PCI device(s).
  76. */
  77. if ((devbusfn = pci_find_devices(supported, 0)) < 0) {
  78. printf("Ti CardBus: not found\n");
  79. return 1;
  80. }
  81. pci_read_config_word(devbusfn, PCI_DEVICE_ID, &dev_id);
  82. if (dev_id == 0xac56) {
  83. debug("Enable PCMCIA Ti PCI1510\n");
  84. } else {
  85. debug("Enable PCMCIA Ti PCI1410A\n");
  86. }
  87. pcmcia_cis_ptr = CONFIG_SYS_PCMCIA_CIS_WIN;
  88. cis_len = CONFIG_SYS_PCMCIA_CIS_WIN_SIZE;
  89. io_base = CONFIG_SYS_PCMCIA_IO_WIN;
  90. io_len = CONFIG_SYS_PCMCIA_IO_WIN_SIZE;
  91. /*
  92. * Setup the PCI device.
  93. */
  94. pci_read_config_dword(devbusfn, PCI_BASE_ADDRESS_0, &socket_base);
  95. socket_base &= ~0xf;
  96. socket_status = readl(socket_base+8);
  97. if ((socket_status & 6) == 0) {
  98. printf("Card Present: ");
  99. switch (socket_status & 0x3c00) {
  100. case 0x400:
  101. printf("5V ");
  102. break;
  103. case 0x800:
  104. printf("3.3V ");
  105. break;
  106. case 0xc00:
  107. printf("3.3/5V ");
  108. break;
  109. default:
  110. printf("unsupported Vcc ");
  111. break;
  112. }
  113. switch (socket_status & 0x30) {
  114. case 0x10:
  115. printf("16bit PC-Card\n");
  116. break;
  117. case 0x20:
  118. printf("32bit CardBus Card\n");
  119. break;
  120. default:
  121. printf("8bit PC-Card\n");
  122. break;
  123. }
  124. }
  125. writeb(0x41, socket_base + 0x806); /* Enable I/O window 0 and memory window 0 */
  126. writeb(0x0e, socket_base + 0x807); /* Reset I/O window options */
  127. /* Careful: the linux yenta driver do not seem to reset the offset
  128. * in the i/o windows, so leaving them non-zero is a problem */
  129. writeb(io_base & 0xff, socket_base + 0x808); /* I/O window 0 base address */
  130. writeb(io_base>>8, socket_base + 0x809);
  131. writeb((io_base + io_len - 1) & 0xff, socket_base + 0x80a); /* I/O window 0 end address */
  132. writeb((io_base + io_len - 1)>>8, socket_base + 0x80b);
  133. writeb(0x00, socket_base + 0x836); /* I/O window 0 offset address 0x000 */
  134. writeb(0x00, socket_base + 0x837);
  135. writeb((pcmcia_cis_ptr&0x000ff000) >> 12,
  136. socket_base + 0x810); /* Memory window 0 start address bits 19-12 */
  137. writeb((pcmcia_cis_ptr&0x00f00000) >> 20,
  138. socket_base + 0x811); /* Memory window 0 start address bits 23-20 */
  139. writeb(((pcmcia_cis_ptr+cis_len-1) & 0x000ff000) >> 12,
  140. socket_base + 0x812); /* Memory window 0 end address bits 19-12*/
  141. writeb(((pcmcia_cis_ptr+cis_len-1) & 0x00f00000) >> 20,
  142. socket_base + 0x813); /* Memory window 0 end address bits 23-20*/
  143. writeb(0x00, socket_base + 0x814); /* Memory window 0 offset bits 19-12 */
  144. writeb(0x40, socket_base + 0x815); /* Memory window 0 offset bits 23-20 and
  145. * options (read/write, attribute access) */
  146. writeb(0x00, socket_base + 0x816); /* ExCA card-detect and general control */
  147. writeb(0x00, socket_base + 0x81e); /* ExCA global control (interrupt modes) */
  148. writeb((pcmcia_cis_ptr & 0xff000000) >> 24,
  149. socket_base + 0x840); /* Memory window address bits 31-24 */
  150. /* turn off voltage */
  151. if (voltage_set(slot, 0, 0)) {
  152. return 1;
  153. }
  154. /* Enable external hardware */
  155. if (hardware_enable(slot)) {
  156. return 1;
  157. }
  158. if (check_ide_device(slot, ide_base_bus)) {
  159. return 1;
  160. }
  161. return 0;
  162. }
  163. /* ------------------------------------------------------------------------- */
  164. #if defined(CONFIG_CMD_PCMCIA)
  165. int pcmcia_off (void)
  166. {
  167. int slot = 0;
  168. writeb(0x00, socket_base + 0x806); /* disable all I/O and memory windows */
  169. writeb(0x00, socket_base + 0x808); /* I/O window 0 base address */
  170. writeb(0x00, socket_base + 0x809);
  171. writeb(0x00, socket_base + 0x80a); /* I/O window 0 end address */
  172. writeb(0x00, socket_base + 0x80b);
  173. writeb(0x00, socket_base + 0x836); /* I/O window 0 offset address */
  174. writeb(0x00, socket_base + 0x837);
  175. writeb(0x00, socket_base + 0x80c); /* I/O window 1 base address */
  176. writeb(0x00, socket_base + 0x80d);
  177. writeb(0x00, socket_base + 0x80e); /* I/O window 1 end address */
  178. writeb(0x00, socket_base + 0x80f);
  179. writeb(0x00, socket_base + 0x838); /* I/O window 1 offset address */
  180. writeb(0x00, socket_base + 0x839);
  181. writeb(0x00, socket_base + 0x810); /* Memory window 0 start address */
  182. writeb(0x00, socket_base + 0x811);
  183. writeb(0x00, socket_base + 0x812); /* Memory window 0 end address */
  184. writeb(0x00, socket_base + 0x813);
  185. writeb(0x00, socket_base + 0x814); /* Memory window 0 offset */
  186. writeb(0x00, socket_base + 0x815);
  187. writeb(0xc0, socket_base + 0x840); /* Memory window 0 page address */
  188. /* turn off voltage */
  189. voltage_set(slot, 0, 0);
  190. /* disable external hardware */
  191. printf ("Shutdown and Poweroff Ti PCI1410A\n");
  192. hardware_disable(slot);
  193. return 0;
  194. }
  195. #endif
  196. /* ------------------------------------------------------------------------- */
  197. #define MAX_TUPEL_SZ 512
  198. #define MAX_FEATURES 4
  199. int ide_devices_found;
  200. static int check_ide_device(int slot, int ide_base_bus)
  201. {
  202. volatile char *ident = NULL;
  203. volatile char *feature_p[MAX_FEATURES];
  204. volatile char *p, *start;
  205. int n_features = 0;
  206. uchar func_id = ~0;
  207. uchar code, len;
  208. ushort config_base = 0;
  209. int found = 0;
  210. int i;
  211. u32 socket_status;
  212. debug ("PCMCIA MEM: %08X\n", pcmcia_cis_ptr);
  213. socket_status = readl(socket_base+8);
  214. if ((socket_status & 6) != 0 || (socket_status & 0x20) != 0) {
  215. printf("no card or CardBus card\n");
  216. return 1;
  217. }
  218. start = p = (volatile char *) pcmcia_cis_ptr;
  219. while ((p - start) < MAX_TUPEL_SZ) {
  220. code = *p; p += 2;
  221. if (code == 0xFF) { /* End of chain */
  222. break;
  223. }
  224. len = *p; p += 2;
  225. #if defined(DEBUG) && (DEBUG > 1)
  226. {
  227. volatile uchar *q = p;
  228. printf ("\nTuple code %02x length %d\n\tData:",
  229. code, len);
  230. for (i = 0; i < len; ++i) {
  231. printf (" %02x", *q);
  232. q+= 2;
  233. }
  234. }
  235. #endif /* DEBUG */
  236. switch (code) {
  237. case CISTPL_VERS_1:
  238. ident = p + 4;
  239. break;
  240. case CISTPL_FUNCID:
  241. /* Fix for broken SanDisk which may have 0x80 bit set */
  242. func_id = *p & 0x7F;
  243. break;
  244. case CISTPL_FUNCE:
  245. if (n_features < MAX_FEATURES)
  246. feature_p[n_features++] = p;
  247. break;
  248. case CISTPL_CONFIG:
  249. config_base = (*(p+6) << 8) + (*(p+4));
  250. debug ("\n## Config_base = %04x ###\n", config_base);
  251. default:
  252. break;
  253. }
  254. p += 2 * len;
  255. }
  256. found = identify(ident);
  257. if (func_id != ((uchar)~0)) {
  258. print_funcid (func_id);
  259. if (func_id == CISTPL_FUNCID_FIXED)
  260. found = 1;
  261. else
  262. return 1; /* no disk drive */
  263. }
  264. for (i=0; i<n_features; ++i) {
  265. print_fixed(feature_p[i]);
  266. }
  267. if (!found) {
  268. printf("unknown card type\n");
  269. return 1;
  270. }
  271. /* select config index 1 */
  272. writeb(1, pcmcia_cis_ptr + config_base);
  273. #if 0
  274. printf("Confiuration Option Register: %02x\n", readb(pcmcia_cis_ptr + config_base));
  275. printf("Card Confiuration and Status Register: %02x\n", readb(pcmcia_cis_ptr + config_base + 2));
  276. printf("Pin Replacement Register Register: %02x\n", readb(pcmcia_cis_ptr + config_base + 4));
  277. printf("Socket and Copy Register: %02x\n", readb(pcmcia_cis_ptr + config_base + 6));
  278. #endif
  279. ide_devices_found |= (1 << (slot+ide_base_bus));
  280. return 0;
  281. }
  282. static int voltage_set(int slot, int vcc, int vpp)
  283. {
  284. u32 socket_control;
  285. int reg=0;
  286. switch (slot) {
  287. case 0:
  288. reg = socket_base + 0x10;
  289. break;
  290. default:
  291. return 1;
  292. }
  293. socket_control = 0;
  294. switch (vcc) {
  295. case 50:
  296. socket_control |= 0x20;
  297. break;
  298. case 33:
  299. socket_control |= 0x30;
  300. break;
  301. case 0:
  302. default: ;
  303. }
  304. switch (vpp) {
  305. case 120:
  306. socket_control |= 0x1;
  307. break;
  308. case 50:
  309. socket_control |= 0x2;
  310. break;
  311. case 33:
  312. socket_control |= 0x3;
  313. break;
  314. case 0:
  315. default: ;
  316. }
  317. writel(socket_control, reg);
  318. debug ("voltage_set: Ti PCI1410A Slot %d, Vcc=%d.%d, Vpp=%d.%d\n",
  319. slot, vcc/10, vcc%10, vpp/10, vpp%10);
  320. udelay(500);
  321. return 0;
  322. }
  323. static int hardware_enable(int slot)
  324. {
  325. u32 socket_status;
  326. u16 brg_ctrl;
  327. int is_82365sl;
  328. socket_status = readl(socket_base+8);
  329. if ((socket_status & 6) == 0) {
  330. switch (socket_status & 0x3c00) {
  331. case 0x400:
  332. printf("5V ");
  333. voltage_set(slot, 50, 0);
  334. break;
  335. case 0x800:
  336. voltage_set(slot, 33, 0);
  337. break;
  338. case 0xc00:
  339. voltage_set(slot, 33, 0);
  340. break;
  341. default:
  342. voltage_set(slot, 0, 0);
  343. break;
  344. }
  345. } else {
  346. voltage_set(slot, 0, 0);
  347. }
  348. pci_read_config_word(devbusfn, PCI_BRIDGE_CONTROL, &brg_ctrl);
  349. brg_ctrl &= ~PCI_BRIDGE_CTL_BUS_RESET;
  350. pci_write_config_word(devbusfn, PCI_BRIDGE_CONTROL, brg_ctrl);
  351. is_82365sl = ((readb(socket_base+0x800) & 0x0f) == 2);
  352. writeb(is_82365sl?0x90:0x98, socket_base+0x802);
  353. writeb(0x67, socket_base+0x803);
  354. udelay(100000);
  355. #if 0
  356. printf("ExCA Id %02x, Card Status %02x, Power config %02x, Interrupt Config %02x, bridge control %04x %d\n",
  357. readb(socket_base+0x800), readb(socket_base+0x801),
  358. readb(socket_base+0x802), readb(socket_base+0x803), brg_ctrl, is_82365sl);
  359. #endif
  360. return ((readb(socket_base+0x801)&0x6c)==0x6c)?0:1;
  361. }
  362. static int hardware_disable(int slot)
  363. {
  364. voltage_set(slot, 0, 0);
  365. return 0;
  366. }
  367. static void print_funcid(int func)
  368. {
  369. puts(indent);
  370. switch (func) {
  371. case CISTPL_FUNCID_MULTI:
  372. puts(" Multi-Function");
  373. break;
  374. case CISTPL_FUNCID_MEMORY:
  375. puts(" Memory");
  376. break;
  377. case CISTPL_FUNCID_SERIAL:
  378. puts(" Serial Port");
  379. break;
  380. case CISTPL_FUNCID_PARALLEL:
  381. puts(" Parallel Port");
  382. break;
  383. case CISTPL_FUNCID_FIXED:
  384. puts(" Fixed Disk");
  385. break;
  386. case CISTPL_FUNCID_VIDEO:
  387. puts(" Video Adapter");
  388. break;
  389. case CISTPL_FUNCID_NETWORK:
  390. puts(" Network Adapter");
  391. break;
  392. case CISTPL_FUNCID_AIMS:
  393. puts(" AIMS Card");
  394. break;
  395. case CISTPL_FUNCID_SCSI:
  396. puts(" SCSI Adapter");
  397. break;
  398. default:
  399. puts(" Unknown");
  400. break;
  401. }
  402. puts(" Card\n");
  403. }
  404. /* ------------------------------------------------------------------------- */
  405. static void print_fixed(volatile char *p)
  406. {
  407. if (p == NULL)
  408. return;
  409. puts(indent);
  410. switch (*p) {
  411. case CISTPL_FUNCE_IDE_IFACE:
  412. { uchar iface = *(p+2);
  413. puts ((iface == CISTPL_IDE_INTERFACE) ? " IDE" : " unknown");
  414. puts (" interface ");
  415. break;
  416. }
  417. case CISTPL_FUNCE_IDE_MASTER:
  418. case CISTPL_FUNCE_IDE_SLAVE:
  419. {
  420. uchar f1 = *(p+2);
  421. uchar f2 = *(p+4);
  422. puts((f1 & CISTPL_IDE_SILICON) ? " [silicon]" : " [rotating]");
  423. if (f1 & CISTPL_IDE_UNIQUE) {
  424. puts(" [unique]");
  425. }
  426. puts((f1 & CISTPL_IDE_DUAL) ? " [dual]" : " [single]");
  427. if (f2 & CISTPL_IDE_HAS_SLEEP) {
  428. puts(" [sleep]");
  429. }
  430. if (f2 & CISTPL_IDE_HAS_STANDBY) {
  431. puts(" [standby]");
  432. }
  433. if (f2 & CISTPL_IDE_HAS_IDLE) {
  434. puts(" [idle]");
  435. }
  436. if (f2 & CISTPL_IDE_LOW_POWER) {
  437. puts(" [low power]");
  438. }
  439. if (f2 & CISTPL_IDE_REG_INHIBIT) {
  440. puts(" [reg inhibit]");
  441. }
  442. if (f2 & CISTPL_IDE_HAS_INDEX) {
  443. puts(" [index]");
  444. }
  445. if (f2 & CISTPL_IDE_IOIS16) {
  446. puts(" [IOis16]");
  447. }
  448. break;
  449. }
  450. }
  451. putc('\n');
  452. }
  453. /* ------------------------------------------------------------------------- */
  454. #define MAX_IDENT_CHARS 64
  455. #define MAX_IDENT_FIELDS 4
  456. static char *known_cards[] = {
  457. "ARGOSY PnPIDE D5",
  458. NULL
  459. };
  460. static int identify(volatile char *p)
  461. {
  462. char id_str[MAX_IDENT_CHARS];
  463. char data;
  464. char *t;
  465. char **card;
  466. int i, done;
  467. if (p == NULL)
  468. return (0); /* Don't know */
  469. t = id_str;
  470. done =0;
  471. for (i=0; i<=4 && !done; ++i, p+=2) {
  472. while ((data = *p) != '\0') {
  473. if (data == 0xFF) {
  474. done = 1;
  475. break;
  476. }
  477. *t++ = data;
  478. if (t == &id_str[MAX_IDENT_CHARS-1]) {
  479. done = 1;
  480. break;
  481. }
  482. p += 2;
  483. }
  484. if (!done)
  485. *t++ = ' ';
  486. }
  487. *t = '\0';
  488. while (--t > id_str) {
  489. if (*t == ' ') {
  490. *t = '\0';
  491. } else {
  492. break;
  493. }
  494. }
  495. puts(id_str);
  496. putc('\n');
  497. for (card=known_cards; *card; ++card) {
  498. debug ("## Compare against \"%s\"\n", *card);
  499. if (strcmp(*card, id_str) == 0) { /* found! */
  500. debug ("## CARD FOUND ##\n");
  501. return 1;
  502. }
  503. }
  504. return 0; /* don't know */
  505. }
  506. #endif /* CONFIG_CMD_PCMCIA */