ti_pci1410a.c 14 KB

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