440spe_pcie.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960
  1. /*
  2. * (C) Copyright 2006
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * Copyright (c) 2005 Cisco Systems. All rights reserved.
  6. * Roland Dreier <rolandd@cisco.com>
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. */
  22. #include <asm/processor.h>
  23. #include <asm-ppc/io.h>
  24. #include <ppc4xx.h>
  25. #include <common.h>
  26. #include <pci.h>
  27. #if defined(CONFIG_440SPE) && defined(CONFIG_PCI)
  28. #include "440spe_pcie.h"
  29. enum {
  30. PTYPE_ENDPOINT = 0x0,
  31. PTYPE_LEGACY_ENDPOINT = 0x1,
  32. PTYPE_ROOT_PORT = 0x4,
  33. LNKW_X1 = 0x1,
  34. LNKW_X4 = 0x4,
  35. LNKW_X8 = 0x8
  36. };
  37. static int pcie_read_config(struct pci_controller *hose, unsigned int devfn,
  38. int offset, int len, u32 *val) {
  39. *val = 0;
  40. /*
  41. * 440SPE implements only one function per port
  42. */
  43. if (!((PCI_FUNC(devfn) == 0) && (PCI_DEV(devfn) == 1)))
  44. return 0;
  45. devfn = PCI_BDF(0,0,0);
  46. offset += devfn << 4;
  47. switch (len) {
  48. case 1:
  49. *val = in_8(hose->cfg_data + offset);
  50. break;
  51. case 2:
  52. *val = in_le16((u16 *)(hose->cfg_data + offset));
  53. break;
  54. default:
  55. *val = in_le32((u32 *)(hose->cfg_data + offset));
  56. break;
  57. }
  58. return 0;
  59. }
  60. static int pcie_write_config(struct pci_controller *hose, unsigned int devfn,
  61. int offset, int len, u32 val) {
  62. /*
  63. * 440SPE implements only one function per port
  64. */
  65. if (!((PCI_FUNC(devfn) == 0) && (PCI_DEV(devfn) == 1)))
  66. return 0;
  67. devfn = PCI_BDF(0,0,0);
  68. offset += devfn << 4;
  69. switch (len) {
  70. case 1:
  71. out_8(hose->cfg_data + offset, val);
  72. break;
  73. case 2:
  74. out_le16((u16 *)(hose->cfg_data + offset), val);
  75. break;
  76. default:
  77. out_le32((u32 *)(hose->cfg_data + offset), val);
  78. break;
  79. }
  80. return 0;
  81. }
  82. int pcie_read_config_byte(struct pci_controller *hose,pci_dev_t dev,int offset,u8 *val)
  83. {
  84. u32 v;
  85. int rv;
  86. rv = pcie_read_config(hose, dev, offset, 1, &v);
  87. *val = (u8)v;
  88. return rv;
  89. }
  90. int pcie_read_config_word(struct pci_controller *hose,pci_dev_t dev,int offset,u16 *val)
  91. {
  92. u32 v;
  93. int rv;
  94. rv = pcie_read_config(hose, dev, offset, 2, &v);
  95. *val = (u16)v;
  96. return rv;
  97. }
  98. int pcie_read_config_dword(struct pci_controller *hose,pci_dev_t dev,int offset,u32 *val)
  99. {
  100. u32 v;
  101. int rv;
  102. rv = pcie_read_config(hose, dev, offset, 3, &v);
  103. *val = (u32)v;
  104. return rv;
  105. }
  106. int pcie_write_config_byte(struct pci_controller *hose,pci_dev_t dev,int offset,u8 val)
  107. {
  108. return pcie_write_config(hose,(u32)dev,offset,1,val);
  109. }
  110. int pcie_write_config_word(struct pci_controller *hose,pci_dev_t dev,int offset,u16 val)
  111. {
  112. return pcie_write_config(hose,(u32)dev,offset,2,(u32 )val);
  113. }
  114. int pcie_write_config_dword(struct pci_controller *hose,pci_dev_t dev,int offset,u32 val)
  115. {
  116. return pcie_write_config(hose,(u32)dev,offset,3,(u32 )val);
  117. }
  118. static void ppc440spe_setup_utl(u32 port) {
  119. volatile void *utl_base = NULL;
  120. /*
  121. * Map UTL registers
  122. */
  123. switch (port) {
  124. case 0:
  125. mtdcr(DCRN_PEGPL_REGBAH(PCIE0), 0x0000000c);
  126. mtdcr(DCRN_PEGPL_REGBAL(PCIE0), 0x20000000);
  127. mtdcr(DCRN_PEGPL_REGMSK(PCIE0), 0x00007001);
  128. mtdcr(DCRN_PEGPL_SPECIAL(PCIE0), 0x68782800);
  129. break;
  130. case 1:
  131. mtdcr(DCRN_PEGPL_REGBAH(PCIE1), 0x0000000c);
  132. mtdcr(DCRN_PEGPL_REGBAL(PCIE1), 0x20001000);
  133. mtdcr(DCRN_PEGPL_REGMSK(PCIE1), 0x00007001);
  134. mtdcr(DCRN_PEGPL_SPECIAL(PCIE1), 0x68782800);
  135. break;
  136. case 2:
  137. mtdcr(DCRN_PEGPL_REGBAH(PCIE2), 0x0000000c);
  138. mtdcr(DCRN_PEGPL_REGBAL(PCIE2), 0x20002000);
  139. mtdcr(DCRN_PEGPL_REGMSK(PCIE2), 0x00007001);
  140. mtdcr(DCRN_PEGPL_SPECIAL(PCIE2), 0x68782800);
  141. break;
  142. }
  143. utl_base = (unsigned int *)(CFG_PCIE_BASE + 0x1000 * port);
  144. /*
  145. * Set buffer allocations and then assert VRB and TXE.
  146. */
  147. out_be32(utl_base + PEUTL_OUTTR, 0x08000000);
  148. out_be32(utl_base + PEUTL_INTR, 0x02000000);
  149. out_be32(utl_base + PEUTL_OPDBSZ, 0x10000000);
  150. out_be32(utl_base + PEUTL_PBBSZ, 0x53000000);
  151. out_be32(utl_base + PEUTL_IPHBSZ, 0x08000000);
  152. out_be32(utl_base + PEUTL_IPDBSZ, 0x10000000);
  153. out_be32(utl_base + PEUTL_RCIRQEN, 0x00f00000);
  154. out_be32(utl_base + PEUTL_PCTL, 0x80800066);
  155. }
  156. static int check_error(void)
  157. {
  158. u32 valPE0, valPE1, valPE2;
  159. int err = 0;
  160. /* SDR0_PEGPLLLCT1 reset */
  161. if (!(valPE0 = SDR_READ(PESDR0_PLLLCT1) & 0x01000000)) {
  162. printf("PCIE: SDR0_PEGPLLLCT1 reset error 0x%x\n", valPE0);
  163. }
  164. valPE0 = SDR_READ(PESDR0_RCSSET);
  165. valPE1 = SDR_READ(PESDR1_RCSSET);
  166. valPE2 = SDR_READ(PESDR2_RCSSET);
  167. /* SDR0_PExRCSSET rstgu */
  168. if (!(valPE0 & 0x01000000) ||
  169. !(valPE1 & 0x01000000) ||
  170. !(valPE2 & 0x01000000)) {
  171. printf("PCIE: SDR0_PExRCSSET rstgu error\n");
  172. err = -1;
  173. }
  174. /* SDR0_PExRCSSET rstdl */
  175. if (!(valPE0 & 0x00010000) ||
  176. !(valPE1 & 0x00010000) ||
  177. !(valPE2 & 0x00010000)) {
  178. printf("PCIE: SDR0_PExRCSSET rstdl error\n");
  179. err = -1;
  180. }
  181. /* SDR0_PExRCSSET rstpyn */
  182. if ((valPE0 & 0x00001000) ||
  183. (valPE1 & 0x00001000) ||
  184. (valPE2 & 0x00001000)) {
  185. printf("PCIE: SDR0_PExRCSSET rstpyn error\n");
  186. err = -1;
  187. }
  188. /* SDR0_PExRCSSET hldplb */
  189. if ((valPE0 & 0x10000000) ||
  190. (valPE1 & 0x10000000) ||
  191. (valPE2 & 0x10000000)) {
  192. printf("PCIE: SDR0_PExRCSSET hldplb error\n");
  193. err = -1;
  194. }
  195. /* SDR0_PExRCSSET rdy */
  196. if ((valPE0 & 0x00100000) ||
  197. (valPE1 & 0x00100000) ||
  198. (valPE2 & 0x00100000)) {
  199. printf("PCIE: SDR0_PExRCSSET rdy error\n");
  200. err = -1;
  201. }
  202. /* SDR0_PExRCSSET shutdown */
  203. if ((valPE0 & 0x00000100) ||
  204. (valPE1 & 0x00000100) ||
  205. (valPE2 & 0x00000100)) {
  206. printf("PCIE: SDR0_PExRCSSET shutdown error\n");
  207. err = -1;
  208. }
  209. return err;
  210. }
  211. /*
  212. * Initialize PCI Express core
  213. */
  214. int ppc440spe_init_pcie(void)
  215. {
  216. int time_out = 20;
  217. /* Set PLL clock receiver to LVPECL */
  218. SDR_WRITE(PESDR0_PLLLCT1, SDR_READ(PESDR0_PLLLCT1) | 1 << 28);
  219. if (check_error())
  220. return -1;
  221. if (!(SDR_READ(PESDR0_PLLLCT2) & 0x10000))
  222. {
  223. printf("PCIE: PESDR_PLLCT2 resistance calibration failed (0x%08x)\n",
  224. SDR_READ(PESDR0_PLLLCT2));
  225. return -1;
  226. }
  227. /* De-assert reset of PCIe PLL, wait for lock */
  228. SDR_WRITE(PESDR0_PLLLCT1, SDR_READ(PESDR0_PLLLCT1) & ~(1 << 24));
  229. udelay(3);
  230. while (time_out) {
  231. if (!(SDR_READ(PESDR0_PLLLCT3) & 0x10000000)) {
  232. time_out--;
  233. udelay(1);
  234. } else
  235. break;
  236. }
  237. if (!time_out) {
  238. printf("PCIE: VCO output not locked\n");
  239. return -1;
  240. }
  241. return 0;
  242. }
  243. /*
  244. * Yucca board as End point and root point setup
  245. * and
  246. * testing inbound and out bound windows
  247. *
  248. * YUCCA board can be plugged into another yucca board or you can get PCI-E
  249. * cable which can be used to setup loop back from one port to another port.
  250. * Please rememeber that unless there is a endpoint plugged in to root port it
  251. * will not initialize. It is the same in case of endpoint , unless there is
  252. * root port attached it will not initialize.
  253. *
  254. * In this release of software all the PCI-E ports are configured as either
  255. * endpoint or rootpoint.In future we will have support for selective ports
  256. * setup as endpoint and root point in single board.
  257. *
  258. * Once your board came up as root point , you can verify by reading
  259. * /proc/bus/pci/devices. Where you can see the configuration registers
  260. * of end point device attached to the port.
  261. *
  262. * Enpoint cofiguration can be verified by connecting Yucca board to any
  263. * host or another yucca board. Then try to scan the device. In case of
  264. * linux use "lspci" or appripriate os command.
  265. *
  266. * How do I verify the inbound and out bound windows ?(yucca to yucca)
  267. * in this configuration inbound and outbound windows are setup to access
  268. * sram memroy area. SRAM is at 0x4 0000 0000 , on PLB bus. This address
  269. * is mapped at 0x90000000. From u-boot prompt write data 0xb000 0000,
  270. * This is waere your POM(PLB out bound memory window) mapped. then
  271. * read the data from other yucca board's u-boot prompt at address
  272. * 0x9000 0000(SRAM). Data should match.
  273. * In case of inbound , write data to u-boot command prompt at 0xb000 0000
  274. * which is mapped to 0x4 0000 0000. Now on rootpoint yucca u-boot prompt check
  275. * data at 0x9000 0000(SRAM).Data should match.
  276. */
  277. int ppc440spe_init_pcie_rootport(int port)
  278. {
  279. static int core_init;
  280. volatile u32 val = 0;
  281. int attempts;
  282. if (!core_init) {
  283. ++core_init;
  284. if (ppc440spe_init_pcie())
  285. return -1;
  286. }
  287. /*
  288. * Initialize various parts of the PCI Express core for our port:
  289. *
  290. * - Set as a root port and enable max width
  291. * (PXIE0 -> X8, PCIE1 and PCIE2 -> X4).
  292. * - Set up UTL configuration.
  293. * - Increase SERDES drive strength to levels suggested by AMCC.
  294. * - De-assert RSTPYN, RSTDL and RSTGU.
  295. *
  296. * NOTICE for revB chip: PESDRn_UTLSET2 is not set - we leave it with
  297. * default setting 0x11310000. The register has new fields,
  298. * PESDRn_UTLSET2[LKINE] in particular: clearing it leads to PCIE core
  299. * hang.
  300. */
  301. switch (port) {
  302. case 0:
  303. SDR_WRITE(PESDR0_DLPSET, 1 << 24 | PTYPE_ROOT_PORT << 20 | LNKW_X8 << 12);
  304. SDR_WRITE(PESDR0_UTLSET1, 0x21222222);
  305. if (!ppc440spe_revB())
  306. SDR_WRITE(PESDR0_UTLSET2, 0x11000000);
  307. SDR_WRITE(PESDR0_HSSL0SET1, 0x35000000);
  308. SDR_WRITE(PESDR0_HSSL1SET1, 0x35000000);
  309. SDR_WRITE(PESDR0_HSSL2SET1, 0x35000000);
  310. SDR_WRITE(PESDR0_HSSL3SET1, 0x35000000);
  311. SDR_WRITE(PESDR0_HSSL4SET1, 0x35000000);
  312. SDR_WRITE(PESDR0_HSSL5SET1, 0x35000000);
  313. SDR_WRITE(PESDR0_HSSL6SET1, 0x35000000);
  314. SDR_WRITE(PESDR0_HSSL7SET1, 0x35000000);
  315. SDR_WRITE(PESDR0_RCSSET,
  316. (SDR_READ(PESDR0_RCSSET) & ~(1 << 24 | 1 << 16)) | 1 << 12);
  317. break;
  318. case 1:
  319. SDR_WRITE(PESDR1_DLPSET, 1 << 24 | PTYPE_ROOT_PORT << 20 | LNKW_X4 << 12);
  320. SDR_WRITE(PESDR1_UTLSET1, 0x21222222);
  321. if (!ppc440spe_revB())
  322. SDR_WRITE(PESDR1_UTLSET2, 0x11000000);
  323. SDR_WRITE(PESDR1_HSSL0SET1, 0x35000000);
  324. SDR_WRITE(PESDR1_HSSL1SET1, 0x35000000);
  325. SDR_WRITE(PESDR1_HSSL2SET1, 0x35000000);
  326. SDR_WRITE(PESDR1_HSSL3SET1, 0x35000000);
  327. SDR_WRITE(PESDR1_RCSSET,
  328. (SDR_READ(PESDR1_RCSSET) & ~(1 << 24 | 1 << 16)) | 1 << 12);
  329. break;
  330. case 2:
  331. SDR_WRITE(PESDR2_DLPSET, 1 << 24 | PTYPE_ROOT_PORT << 20 | LNKW_X4 << 12);
  332. SDR_WRITE(PESDR2_UTLSET1, 0x21222222);
  333. if (!ppc440spe_revB())
  334. SDR_WRITE(PESDR2_UTLSET2, 0x11000000);
  335. SDR_WRITE(PESDR2_HSSL0SET1, 0x35000000);
  336. SDR_WRITE(PESDR2_HSSL1SET1, 0x35000000);
  337. SDR_WRITE(PESDR2_HSSL2SET1, 0x35000000);
  338. SDR_WRITE(PESDR2_HSSL3SET1, 0x35000000);
  339. SDR_WRITE(PESDR2_RCSSET,
  340. (SDR_READ(PESDR2_RCSSET) & ~(1 << 24 | 1 << 16)) | 1 << 12);
  341. break;
  342. }
  343. /*
  344. * Notice: the following delay has critical impact on device
  345. * initialization - if too short (<50ms) the link doesn't get up.
  346. */
  347. mdelay(100);
  348. switch (port) {
  349. case 0:
  350. val = SDR_READ(PESDR0_RCSSTS);
  351. break;
  352. case 1:
  353. val = SDR_READ(PESDR1_RCSSTS);
  354. break;
  355. case 2:
  356. val = SDR_READ(PESDR2_RCSSTS);
  357. break;
  358. }
  359. if (val & (1 << 20)) {
  360. printf("PCIE%d: PGRST failed %08x\n", port, val);
  361. return -1;
  362. }
  363. /*
  364. * Verify link is up
  365. */
  366. val = 0;
  367. switch (port) {
  368. case 0:
  369. val = SDR_READ(PESDR0_LOOP);
  370. break;
  371. case 1:
  372. val = SDR_READ(PESDR1_LOOP);
  373. break;
  374. case 2:
  375. val = SDR_READ(PESDR2_LOOP);
  376. break;
  377. }
  378. if (!(val & 0x00001000)) {
  379. printf("PCIE%d: link is not up.\n", port);
  380. return -1;
  381. }
  382. /*
  383. * Setup UTL registers - but only on revA!
  384. * We use default settings for revB chip.
  385. */
  386. if (!ppc440spe_revB())
  387. ppc440spe_setup_utl(port);
  388. /*
  389. * We map PCI Express configuration access into the 512MB regions
  390. *
  391. * NOTICE: revB is very strict about PLB real addressess and ranges to
  392. * be mapped for config space; it seems to only work with d_nnnn_nnnn
  393. * range (hangs the core upon config transaction attempts when set
  394. * otherwise) while revA uses c_nnnn_nnnn.
  395. *
  396. * For revA:
  397. * PCIE0: 0xc_4000_0000
  398. * PCIE1: 0xc_8000_0000
  399. * PCIE2: 0xc_c000_0000
  400. *
  401. * For revB:
  402. * PCIE0: 0xd_0000_0000
  403. * PCIE1: 0xd_2000_0000
  404. * PCIE2: 0xd_4000_0000
  405. */
  406. switch (port) {
  407. case 0:
  408. if (ppc440spe_revB()) {
  409. mtdcr(DCRN_PEGPL_CFGBAH(PCIE0), 0x0000000d);
  410. mtdcr(DCRN_PEGPL_CFGBAL(PCIE0), 0x00000000);
  411. } else {
  412. /* revA */
  413. mtdcr(DCRN_PEGPL_CFGBAH(PCIE0), 0x0000000c);
  414. mtdcr(DCRN_PEGPL_CFGBAL(PCIE0), 0x40000000);
  415. }
  416. mtdcr(DCRN_PEGPL_CFGMSK(PCIE0), 0xe0000001); /* 512MB region, valid */
  417. break;
  418. case 1:
  419. if (ppc440spe_revB()) {
  420. mtdcr(DCRN_PEGPL_CFGBAH(PCIE1), 0x0000000d);
  421. mtdcr(DCRN_PEGPL_CFGBAL(PCIE1), 0x20000000);
  422. } else {
  423. mtdcr(DCRN_PEGPL_CFGBAH(PCIE1), 0x0000000c);
  424. mtdcr(DCRN_PEGPL_CFGBAL(PCIE1), 0x80000000);
  425. }
  426. mtdcr(DCRN_PEGPL_CFGMSK(PCIE1), 0xe0000001); /* 512MB region, valid */
  427. break;
  428. case 2:
  429. if (ppc440spe_revB()) {
  430. mtdcr(DCRN_PEGPL_CFGBAH(PCIE2), 0x0000000d);
  431. mtdcr(DCRN_PEGPL_CFGBAL(PCIE2), 0x40000000);
  432. } else {
  433. mtdcr(DCRN_PEGPL_CFGBAH(PCIE2), 0x0000000c);
  434. mtdcr(DCRN_PEGPL_CFGBAL(PCIE2), 0xc0000000);
  435. }
  436. mtdcr(DCRN_PEGPL_CFGMSK(PCIE2), 0xe0000001); /* 512MB region, valid */
  437. break;
  438. }
  439. /*
  440. * Check for VC0 active and assert RDY.
  441. */
  442. attempts = 10;
  443. switch (port) {
  444. case 0:
  445. while(!(SDR_READ(PESDR0_RCSSTS) & (1 << 16))) {
  446. if (!(attempts--)) {
  447. printf("PCIE0: VC0 not active\n");
  448. return -1;
  449. }
  450. mdelay(1000);
  451. }
  452. SDR_WRITE(PESDR0_RCSSET, SDR_READ(PESDR0_RCSSET) | 1 << 20);
  453. break;
  454. case 1:
  455. while(!(SDR_READ(PESDR1_RCSSTS) & (1 << 16))) {
  456. if (!(attempts--)) {
  457. printf("PCIE1: VC0 not active\n");
  458. return -1;
  459. }
  460. mdelay(1000);
  461. }
  462. SDR_WRITE(PESDR1_RCSSET, SDR_READ(PESDR1_RCSSET) | 1 << 20);
  463. break;
  464. case 2:
  465. while(!(SDR_READ(PESDR2_RCSSTS) & (1 << 16))) {
  466. if (!(attempts--)) {
  467. printf("PCIE2: VC0 not active\n");
  468. return -1;
  469. }
  470. mdelay(1000);
  471. }
  472. SDR_WRITE(PESDR2_RCSSET, SDR_READ(PESDR2_RCSSET) | 1 << 20);
  473. break;
  474. }
  475. mdelay(100);
  476. return 0;
  477. }
  478. int ppc440spe_init_pcie_endport(int port)
  479. {
  480. static int core_init;
  481. volatile u32 val = 0;
  482. int attempts;
  483. if (!core_init) {
  484. ++core_init;
  485. if (ppc440spe_init_pcie())
  486. return -1;
  487. }
  488. /*
  489. * Initialize various parts of the PCI Express core for our port:
  490. *
  491. * - Set as a end port and enable max width
  492. * (PXIE0 -> X8, PCIE1 and PCIE2 -> X4).
  493. * - Set up UTL configuration.
  494. * - Increase SERDES drive strength to levels suggested by AMCC.
  495. * - De-assert RSTPYN, RSTDL and RSTGU.
  496. *
  497. * NOTICE for revB chip: PESDRn_UTLSET2 is not set - we leave it with
  498. * default setting 0x11310000. The register has new fields,
  499. * PESDRn_UTLSET2[LKINE] in particular: clearing it leads to PCIE core
  500. * hang.
  501. */
  502. switch (port) {
  503. case 0:
  504. SDR_WRITE(PESDR0_DLPSET, 1 << 24 | PTYPE_LEGACY_ENDPOINT << 20 | LNKW_X8 << 12);
  505. SDR_WRITE(PESDR0_UTLSET1, 0x20222222);
  506. if (!ppc440spe_revB())
  507. SDR_WRITE(PESDR0_UTLSET2, 0x11000000);
  508. SDR_WRITE(PESDR0_HSSL0SET1, 0x35000000);
  509. SDR_WRITE(PESDR0_HSSL1SET1, 0x35000000);
  510. SDR_WRITE(PESDR0_HSSL2SET1, 0x35000000);
  511. SDR_WRITE(PESDR0_HSSL3SET1, 0x35000000);
  512. SDR_WRITE(PESDR0_HSSL4SET1, 0x35000000);
  513. SDR_WRITE(PESDR0_HSSL5SET1, 0x35000000);
  514. SDR_WRITE(PESDR0_HSSL6SET1, 0x35000000);
  515. SDR_WRITE(PESDR0_HSSL7SET1, 0x35000000);
  516. SDR_WRITE(PESDR0_RCSSET,
  517. (SDR_READ(PESDR0_RCSSET) & ~(1 << 24 | 1 << 16)) | 1 << 12);
  518. break;
  519. case 1:
  520. SDR_WRITE(PESDR1_DLPSET, 1 << 24 | PTYPE_LEGACY_ENDPOINT << 20 | LNKW_X4 << 12);
  521. SDR_WRITE(PESDR1_UTLSET1, 0x20222222);
  522. if (!ppc440spe_revB())
  523. SDR_WRITE(PESDR1_UTLSET2, 0x11000000);
  524. SDR_WRITE(PESDR1_HSSL0SET1, 0x35000000);
  525. SDR_WRITE(PESDR1_HSSL1SET1, 0x35000000);
  526. SDR_WRITE(PESDR1_HSSL2SET1, 0x35000000);
  527. SDR_WRITE(PESDR1_HSSL3SET1, 0x35000000);
  528. SDR_WRITE(PESDR1_RCSSET,
  529. (SDR_READ(PESDR1_RCSSET) & ~(1 << 24 | 1 << 16)) | 1 << 12);
  530. break;
  531. case 2:
  532. SDR_WRITE(PESDR2_DLPSET, 1 << 24 | PTYPE_LEGACY_ENDPOINT << 20 | LNKW_X4 << 12);
  533. SDR_WRITE(PESDR2_UTLSET1, 0x20222222);
  534. if (!ppc440spe_revB())
  535. SDR_WRITE(PESDR2_UTLSET2, 0x11000000);
  536. SDR_WRITE(PESDR2_HSSL0SET1, 0x35000000);
  537. SDR_WRITE(PESDR2_HSSL1SET1, 0x35000000);
  538. SDR_WRITE(PESDR2_HSSL2SET1, 0x35000000);
  539. SDR_WRITE(PESDR2_HSSL3SET1, 0x35000000);
  540. SDR_WRITE(PESDR2_RCSSET,
  541. (SDR_READ(PESDR2_RCSSET) & ~(1 << 24 | 1 << 16)) | 1 << 12);
  542. break;
  543. }
  544. /*
  545. * Notice: the following delay has critical impact on device
  546. * initialization - if too short (<50ms) the link doesn't get up.
  547. */
  548. mdelay(100);
  549. switch (port) {
  550. case 0: val = SDR_READ(PESDR0_RCSSTS); break;
  551. case 1: val = SDR_READ(PESDR1_RCSSTS); break;
  552. case 2: val = SDR_READ(PESDR2_RCSSTS); break;
  553. }
  554. if (val & (1 << 20)) {
  555. printf("PCIE%d: PGRST failed %08x\n", port, val);
  556. return -1;
  557. }
  558. /*
  559. * Verify link is up
  560. */
  561. val = 0;
  562. switch (port)
  563. {
  564. case 0:
  565. val = SDR_READ(PESDR0_LOOP);
  566. break;
  567. case 1:
  568. val = SDR_READ(PESDR1_LOOP);
  569. break;
  570. case 2:
  571. val = SDR_READ(PESDR2_LOOP);
  572. break;
  573. }
  574. if (!(val & 0x00001000)) {
  575. printf("PCIE%d: link is not up.\n", port);
  576. return -1;
  577. }
  578. /*
  579. * Setup UTL registers - but only on revA!
  580. * We use default settings for revB chip.
  581. */
  582. if (!ppc440spe_revB())
  583. ppc440spe_setup_utl(port);
  584. /*
  585. * We map PCI Express configuration access into the 512MB regions
  586. *
  587. * NOTICE: revB is very strict about PLB real addressess and ranges to
  588. * be mapped for config space; it seems to only work with d_nnnn_nnnn
  589. * range (hangs the core upon config transaction attempts when set
  590. * otherwise) while revA uses c_nnnn_nnnn.
  591. *
  592. * For revA:
  593. * PCIE0: 0xc_4000_0000
  594. * PCIE1: 0xc_8000_0000
  595. * PCIE2: 0xc_c000_0000
  596. *
  597. * For revB:
  598. * PCIE0: 0xd_0000_0000
  599. * PCIE1: 0xd_2000_0000
  600. * PCIE2: 0xd_4000_0000
  601. */
  602. switch (port) {
  603. case 0:
  604. if (ppc440spe_revB()) {
  605. mtdcr(DCRN_PEGPL_CFGBAH(PCIE0), 0x0000000d);
  606. mtdcr(DCRN_PEGPL_CFGBAL(PCIE0), 0x00000000);
  607. } else {
  608. /* revA */
  609. mtdcr(DCRN_PEGPL_CFGBAH(PCIE0), 0x0000000c);
  610. mtdcr(DCRN_PEGPL_CFGBAL(PCIE0), 0x40000000);
  611. }
  612. mtdcr(DCRN_PEGPL_CFGMSK(PCIE0), 0xe0000001); /* 512MB region, valid */
  613. break;
  614. case 1:
  615. if (ppc440spe_revB()) {
  616. mtdcr(DCRN_PEGPL_CFGBAH(PCIE1), 0x0000000d);
  617. mtdcr(DCRN_PEGPL_CFGBAL(PCIE1), 0x20000000);
  618. } else {
  619. mtdcr(DCRN_PEGPL_CFGBAH(PCIE1), 0x0000000c);
  620. mtdcr(DCRN_PEGPL_CFGBAL(PCIE1), 0x80000000);
  621. }
  622. mtdcr(DCRN_PEGPL_CFGMSK(PCIE1), 0xe0000001); /* 512MB region, valid */
  623. break;
  624. case 2:
  625. if (ppc440spe_revB()) {
  626. mtdcr(DCRN_PEGPL_CFGBAH(PCIE2), 0x0000000d);
  627. mtdcr(DCRN_PEGPL_CFGBAL(PCIE2), 0x40000000);
  628. } else {
  629. mtdcr(DCRN_PEGPL_CFGBAH(PCIE2), 0x0000000c);
  630. mtdcr(DCRN_PEGPL_CFGBAL(PCIE2), 0xc0000000);
  631. }
  632. mtdcr(DCRN_PEGPL_CFGMSK(PCIE2), 0xe0000001); /* 512MB region, valid */
  633. break;
  634. }
  635. /*
  636. * Check for VC0 active and assert RDY.
  637. */
  638. attempts = 10;
  639. switch (port) {
  640. case 0:
  641. while(!(SDR_READ(PESDR0_RCSSTS) & (1 << 16))) {
  642. if (!(attempts--)) {
  643. printf("PCIE0: VC0 not active\n");
  644. return -1;
  645. }
  646. mdelay(1000);
  647. }
  648. SDR_WRITE(PESDR0_RCSSET, SDR_READ(PESDR0_RCSSET) | 1 << 20);
  649. break;
  650. case 1:
  651. while(!(SDR_READ(PESDR1_RCSSTS) & (1 << 16))) {
  652. if (!(attempts--)) {
  653. printf("PCIE1: VC0 not active\n");
  654. return -1;
  655. }
  656. mdelay(1000);
  657. }
  658. SDR_WRITE(PESDR1_RCSSET, SDR_READ(PESDR1_RCSSET) | 1 << 20);
  659. break;
  660. case 2:
  661. while(!(SDR_READ(PESDR2_RCSSTS) & (1 << 16))) {
  662. if (!(attempts--)) {
  663. printf("PCIE2: VC0 not active\n");
  664. return -1;
  665. }
  666. mdelay(1000);
  667. }
  668. SDR_WRITE(PESDR2_RCSSET, SDR_READ(PESDR2_RCSSET) | 1 << 20);
  669. break;
  670. }
  671. mdelay(100);
  672. return 0;
  673. }
  674. void ppc440spe_setup_pcie_rootpoint(struct pci_controller *hose, int port)
  675. {
  676. volatile void *mbase = NULL;
  677. volatile void *rmbase = NULL;
  678. pci_set_ops(hose,
  679. pcie_read_config_byte,
  680. pcie_read_config_word,
  681. pcie_read_config_dword,
  682. pcie_write_config_byte,
  683. pcie_write_config_word,
  684. pcie_write_config_dword);
  685. switch (port) {
  686. case 0:
  687. mbase = (u32 *)CFG_PCIE0_XCFGBASE;
  688. rmbase = (u32 *)CFG_PCIE0_CFGBASE;
  689. hose->cfg_data = (u8 *)CFG_PCIE0_CFGBASE;
  690. break;
  691. case 1:
  692. mbase = (u32 *)CFG_PCIE1_XCFGBASE;
  693. rmbase = (u32 *)CFG_PCIE1_CFGBASE;
  694. hose->cfg_data = (u8 *)CFG_PCIE1_CFGBASE;
  695. break;
  696. case 2:
  697. mbase = (u32 *)CFG_PCIE2_XCFGBASE;
  698. rmbase = (u32 *)CFG_PCIE2_CFGBASE;
  699. hose->cfg_data = (u8 *)CFG_PCIE2_CFGBASE;
  700. break;
  701. }
  702. /*
  703. * Set bus numbers on our root port
  704. */
  705. out_8((u8 *)mbase + PCI_PRIMARY_BUS, 0);
  706. out_8((u8 *)mbase + PCI_SECONDARY_BUS, 1);
  707. out_8((u8 *)mbase + PCI_SUBORDINATE_BUS, 1);
  708. /*
  709. * Set up outbound translation to hose->mem_space from PLB
  710. * addresses at an offset of 0xd_0000_0000. We set the low
  711. * bits of the mask to 11 to turn off splitting into 8
  712. * subregions and to enable the outbound translation.
  713. */
  714. out_le32(mbase + PECFG_POM0LAH, 0x00000000);
  715. out_le32(mbase + PECFG_POM0LAL, 0x00000000);
  716. switch (port) {
  717. case 0:
  718. mtdcr(DCRN_PEGPL_OMR1BAH(PCIE0), 0x0000000d);
  719. mtdcr(DCRN_PEGPL_OMR1BAL(PCIE0), CFG_PCIE_MEMBASE +
  720. port * CFG_PCIE_MEMSIZE);
  721. mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE0), 0x7fffffff);
  722. mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE0),
  723. ~(CFG_PCIE_MEMSIZE - 1) | 3);
  724. break;
  725. case 1:
  726. mtdcr(DCRN_PEGPL_OMR1BAH(PCIE1), 0x0000000d);
  727. mtdcr(DCRN_PEGPL_OMR1BAL(PCIE1), (CFG_PCIE_MEMBASE +
  728. port * CFG_PCIE_MEMSIZE));
  729. mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE1), 0x7fffffff);
  730. mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE1),
  731. ~(CFG_PCIE_MEMSIZE - 1) | 3);
  732. break;
  733. case 2:
  734. mtdcr(DCRN_PEGPL_OMR1BAH(PCIE2), 0x0000000d);
  735. mtdcr(DCRN_PEGPL_OMR1BAL(PCIE2), (CFG_PCIE_MEMBASE +
  736. port * CFG_PCIE_MEMSIZE));
  737. mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE2), 0x7fffffff);
  738. mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE2),
  739. ~(CFG_PCIE_MEMSIZE - 1) | 3);
  740. break;
  741. }
  742. /* Set up 16GB inbound memory window at 0 */
  743. out_le32(mbase + PCI_BASE_ADDRESS_0, 0);
  744. out_le32(mbase + PCI_BASE_ADDRESS_1, 0);
  745. out_le32(mbase + PECFG_BAR0HMPA, 0x7fffffc);
  746. out_le32(mbase + PECFG_BAR0LMPA, 0);
  747. out_le32(mbase + PECFG_PIM01SAH, 0xffff0000);
  748. out_le32(mbase + PECFG_PIM01SAL, 0x00000000);
  749. out_le32(mbase + PECFG_PIM0LAL, 0);
  750. out_le32(mbase + PECFG_PIM0LAH, 0);
  751. out_le32(mbase + PECFG_PIM1LAL, 0x00000000);
  752. out_le32(mbase + PECFG_PIM1LAH, 0x00000004);
  753. out_le32(mbase + PECFG_PIMEN, 0x1);
  754. /* Enable I/O, Mem, and Busmaster cycles */
  755. out_le16((u16 *)(mbase + PCI_COMMAND),
  756. in_le16((u16 *)(mbase + PCI_COMMAND)) |
  757. PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
  758. printf("PCIE:%d successfully set as rootpoint\n",port);
  759. }
  760. int ppc440spe_setup_pcie_endpoint(struct pci_controller *hose, int port)
  761. {
  762. volatile void *mbase = NULL;
  763. int attempts = 0;
  764. pci_set_ops(hose,
  765. pcie_read_config_byte,
  766. pcie_read_config_word,
  767. pcie_read_config_dword,
  768. pcie_write_config_byte,
  769. pcie_write_config_word,
  770. pcie_write_config_dword);
  771. switch (port) {
  772. case 0:
  773. mbase = (u32 *)CFG_PCIE0_XCFGBASE;
  774. hose->cfg_data = (u8 *)CFG_PCIE0_CFGBASE;
  775. break;
  776. case 1:
  777. mbase = (u32 *)CFG_PCIE1_XCFGBASE;
  778. hose->cfg_data = (u8 *)CFG_PCIE1_CFGBASE;
  779. break;
  780. case 2:
  781. mbase = (u32 *)CFG_PCIE2_XCFGBASE;
  782. hose->cfg_data = (u8 *)CFG_PCIE2_CFGBASE;
  783. break;
  784. }
  785. /*
  786. * Set up outbound translation to hose->mem_space from PLB
  787. * addresses at an offset of 0xd_0000_0000. We set the low
  788. * bits of the mask to 11 to turn off splitting into 8
  789. * subregions and to enable the outbound translation.
  790. */
  791. out_le32(mbase + PECFG_POM0LAH, 0x00001ff8);
  792. out_le32(mbase + PECFG_POM0LAL, 0x00001000);
  793. switch (port) {
  794. case 0:
  795. mtdcr(DCRN_PEGPL_OMR1BAH(PCIE0), 0x0000000d);
  796. mtdcr(DCRN_PEGPL_OMR1BAL(PCIE0), CFG_PCIE_MEMBASE +
  797. port * CFG_PCIE_MEMSIZE);
  798. mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE0), 0x7fffffff);
  799. mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE0),
  800. ~(CFG_PCIE_MEMSIZE - 1) | 3);
  801. break;
  802. case 1:
  803. mtdcr(DCRN_PEGPL_OMR1BAH(PCIE1), 0x0000000d);
  804. mtdcr(DCRN_PEGPL_OMR1BAL(PCIE1), (CFG_PCIE_MEMBASE +
  805. port * CFG_PCIE_MEMSIZE));
  806. mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE1), 0x7fffffff);
  807. mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE1),
  808. ~(CFG_PCIE_MEMSIZE - 1) | 3);
  809. break;
  810. case 2:
  811. mtdcr(DCRN_PEGPL_OMR1BAH(PCIE2), 0x0000000d);
  812. mtdcr(DCRN_PEGPL_OMR1BAL(PCIE2), (CFG_PCIE_MEMBASE +
  813. port * CFG_PCIE_MEMSIZE));
  814. mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE2), 0x7fffffff);
  815. mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE2),
  816. ~(CFG_PCIE_MEMSIZE - 1) | 3);
  817. break;
  818. }
  819. /* Set up 16GB inbound memory window at 0 */
  820. out_le32(mbase + PCI_BASE_ADDRESS_0, 0);
  821. out_le32(mbase + PCI_BASE_ADDRESS_1, 0);
  822. out_le32(mbase + PECFG_BAR0HMPA, 0x7fffffc);
  823. out_le32(mbase + PECFG_BAR0LMPA, 0);
  824. out_le32(mbase + PECFG_PIM0LAL, 0x00000000);
  825. out_le32(mbase + PECFG_PIM0LAH, 0x00000004); /* pointing to SRAM */
  826. out_le32(mbase + PECFG_PIMEN, 0x1);
  827. /* Enable I/O, Mem, and Busmaster cycles */
  828. out_le16((u16 *)(mbase + PCI_COMMAND),
  829. in_le16((u16 *)(mbase + PCI_COMMAND)) |
  830. PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
  831. out_le16(mbase + 0x200,0xcaad); /* Setting vendor ID */
  832. out_le16(mbase + 0x202,0xfeed); /* Setting device ID */
  833. attempts = 10;
  834. switch (port) {
  835. case 0:
  836. while (!(SDR_READ(PESDR0_RCSSTS) & (1 << 8))) {
  837. if (!(attempts--)) {
  838. printf("PCIE0: BMEN is not active\n");
  839. return -1;
  840. }
  841. mdelay(1000);
  842. }
  843. break;
  844. case 1:
  845. while (!(SDR_READ(PESDR1_RCSSTS) & (1 << 8))) {
  846. if (!(attempts--)) {
  847. printf("PCIE1: BMEN is not active\n");
  848. return -1;
  849. }
  850. mdelay(1000);
  851. }
  852. break;
  853. case 2:
  854. while (!(SDR_READ(PESDR2_RCSSTS) & (1 << 8))) {
  855. if (!(attempts--)) {
  856. printf("PCIE2: BMEN is not active\n");
  857. return -1;
  858. }
  859. mdelay(1000);
  860. }
  861. break;
  862. }
  863. printf("PCIE:%d successfully set as endpoint\n",port);
  864. return 0;
  865. }
  866. #endif /* CONFIG_440SPE && CONFIG_PCI */