ti_pci1410a.c 15 KB

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