integratorap.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. /*
  2. * (C) Copyright 2002
  3. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  4. * Marius Groeger <mgroeger@sysgo.de>
  5. *
  6. * (C) Copyright 2002
  7. * David Mueller, ELSOFT AG, <d.mueller@elsoft.ch>
  8. *
  9. * (C) Copyright 2003
  10. * Texas Instruments, <www.ti.com>
  11. * Kshitij Gupta <Kshitij@ti.com>
  12. *
  13. * (C) Copyright 2004
  14. * ARM Ltd.
  15. * Philippe Robin, <philippe.robin@arm.com>
  16. *
  17. * See file CREDITS for list of people who contributed to this
  18. * project.
  19. *
  20. * This program is free software; you can redistribute it and/or
  21. * modify it under the terms of the GNU General Public License as
  22. * published by the Free Software Foundation; either version 2 of
  23. * the License, or (at your option) any later version.
  24. *
  25. * This program is distributed in the hope that it will be useful,
  26. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  27. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  28. * GNU General Public License for more details.
  29. *
  30. * You should have received a copy of the GNU General Public License
  31. * along with this program; if not, write to the Free Software
  32. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  33. * MA 02111-1307 USA
  34. */
  35. #include <common.h>
  36. #ifdef CONFIG_PCI
  37. # include <pci.h>
  38. #endif
  39. void flash__init (void);
  40. void ether__init (void);
  41. void peripheral_power_enable (void);
  42. #if defined(CONFIG_SHOW_BOOT_PROGRESS)
  43. void show_boot_progress(int progress)
  44. {
  45. printf("Boot reached stage %d\n", progress);
  46. }
  47. #endif
  48. #define COMP_MODE_ENABLE ((unsigned int)0x0000EAEF)
  49. static inline void delay (unsigned long loops)
  50. {
  51. __asm__ volatile ("1:\n"
  52. "subs %0, %1, #1\n"
  53. "bne 1b":"=r" (loops):"0" (loops));
  54. }
  55. /*
  56. * Miscellaneous platform dependent initialisations
  57. */
  58. int board_init (void)
  59. {
  60. DECLARE_GLOBAL_DATA_PTR;
  61. /* arch number of Integrator Board */
  62. gd->bd->bi_arch_number = 21;
  63. /* adress of boot parameters */
  64. gd->bd->bi_boot_params = 0x00000100;
  65. icache_enable ();
  66. flash__init ();
  67. return 0;
  68. }
  69. int misc_init_r (void)
  70. {
  71. #ifdef CONFIG_PCI
  72. pci_init();
  73. #endif
  74. setenv("verify", "n");
  75. return (0);
  76. }
  77. /*
  78. * Initialize PCI Devices, report devices found.
  79. */
  80. #ifdef CONFIG_PCI
  81. #ifndef CONFIG_PCI_PNP
  82. static struct pci_config_table pci_integrator_config_table[] = {
  83. { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 0x0f, PCI_ANY_ID,
  84. pci_cfgfunc_config_device, { PCI_ENET0_IOADDR,
  85. PCI_ENET0_MEMADDR,
  86. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER }},
  87. { }
  88. };
  89. #endif
  90. /* V3 access routines */
  91. #define _V3Write16(o,v) (*(volatile unsigned short *)(PCI_V3_BASE + (unsigned int)(o)) = (unsigned short)(v))
  92. #define _V3Read16(o) (*(volatile unsigned short *)(PCI_V3_BASE + (unsigned int)(o)))
  93. #define _V3Write32(o,v) (*(volatile unsigned int *)(PCI_V3_BASE + (unsigned int)(o)) = (unsigned int)(v))
  94. #define _V3Read32(o) (*(volatile unsigned int *)(PCI_V3_BASE + (unsigned int)(o)))
  95. /* Compute address necessary to access PCI config space for the given */
  96. /* bus and device. */
  97. #define PCI_CONFIG_ADDRESS( __bus, __devfn, __offset ) ({ \
  98. unsigned int __address, __devicebit; \
  99. unsigned short __mapaddress; \
  100. unsigned int __dev = PCI_DEV (__devfn); /* FIXME to check!! (slot?) */ \
  101. \
  102. if (__bus == 0) { \
  103. /* local bus segment so need a type 0 config cycle */ \
  104. /* build the PCI configuration "address" with one-hot in A31-A11 */ \
  105. __address = PCI_CONFIG_BASE; \
  106. __address |= ((__devfn & 0x07) << 8); \
  107. __address |= __offset & 0xFF; \
  108. __mapaddress = 0x000A; /* 101=>config cycle, 0=>A1=A0=0 */ \
  109. __devicebit = (1 << (__dev + 11)); \
  110. \
  111. if ((__devicebit & 0xFF000000) != 0) { \
  112. /* high order bits are handled by the MAP register */ \
  113. __mapaddress |= (__devicebit >> 16); \
  114. } else { \
  115. /* low order bits handled directly in the address */ \
  116. __address |= __devicebit; \
  117. } \
  118. } else { /* bus !=0 */ \
  119. /* not the local bus segment so need a type 1 config cycle */ \
  120. /* A31-A24 are don't care (so clear to 0) */ \
  121. __mapaddress = 0x000B; /* 101=>config cycle, 1=>A1&A0 from PCI_CFG */ \
  122. __address = PCI_CONFIG_BASE; \
  123. __address |= ((__bus & 0xFF) << 16); /* bits 23..16 = bus number */ \
  124. __address |= ((__dev & 0x1F) << 11); /* bits 15..11 = device number */ \
  125. __address |= ((__devfn & 0x07) << 8); /* bits 10..8 = function number */ \
  126. __address |= __offset & 0xFF; /* bits 7..0 = register number */ \
  127. } \
  128. _V3Write16 (V3_LB_MAP1, __mapaddress); \
  129. __address; \
  130. })
  131. /* _V3OpenConfigWindow - open V3 configuration window */
  132. #define _V3OpenConfigWindow() { \
  133. /* Set up base0 to see all 512Mbytes of memory space (not */ \
  134. /* prefetchable), this frees up base1 for re-use by configuration*/ \
  135. /* memory */ \
  136. \
  137. _V3Write32 (V3_LB_BASE0, ((INTEGRATOR_PCI_BASE & 0xFFF00000) | \
  138. 0x90 | V3_LB_BASE_M_ENABLE)); \
  139. /* Set up base1 to point into configuration space, note that MAP1 */ \
  140. /* register is set up by pciMakeConfigAddress(). */ \
  141. \
  142. _V3Write32 (V3_LB_BASE1, ((CPU_PCI_CNFG_ADRS & 0xFFF00000) | \
  143. 0x40 | V3_LB_BASE_M_ENABLE)); \
  144. }
  145. /* _V3CloseConfigWindow - close V3 configuration window */
  146. #define _V3CloseConfigWindow() { \
  147. /* Reassign base1 for use by prefetchable PCI memory */ \
  148. _V3Write32 (V3_LB_BASE1, (((INTEGRATOR_PCI_BASE + 0x10000000) & 0xFFF00000) \
  149. | 0x84 | V3_LB_BASE_M_ENABLE)); \
  150. _V3Write16 (V3_LB_MAP1, \
  151. (((INTEGRATOR_PCI_BASE + 0x10000000) & 0xFFF00000) >> 16) | 0x0006); \
  152. \
  153. /* And shrink base0 back to a 256M window (NOTE: MAP0 already correct) */ \
  154. \
  155. _V3Write32 (V3_LB_BASE0, ((INTEGRATOR_PCI_BASE & 0xFFF00000) | \
  156. 0x80 | V3_LB_BASE_M_ENABLE)); \
  157. }
  158. static int pci_integrator_read_byte (struct pci_controller *hose, pci_dev_t dev,
  159. int offset, unsigned char *val)
  160. {
  161. _V3OpenConfigWindow ();
  162. *val = *(volatile unsigned char *) PCI_CONFIG_ADDRESS (PCI_BUS (dev),
  163. PCI_FUNC (dev),
  164. offset);
  165. _V3CloseConfigWindow ();
  166. return 0;
  167. }
  168. static int pci_integrator_read__word (struct pci_controller *hose,
  169. pci_dev_t dev, int offset,
  170. unsigned short *val)
  171. {
  172. _V3OpenConfigWindow ();
  173. *val = *(volatile unsigned short *) PCI_CONFIG_ADDRESS (PCI_BUS (dev),
  174. PCI_FUNC (dev),
  175. offset);
  176. _V3CloseConfigWindow ();
  177. return 0;
  178. }
  179. static int pci_integrator_read_dword (struct pci_controller *hose,
  180. pci_dev_t dev, int offset,
  181. unsigned int *val)
  182. {
  183. _V3OpenConfigWindow ();
  184. *val = *(volatile unsigned short *) PCI_CONFIG_ADDRESS (PCI_BUS (dev),
  185. PCI_FUNC (dev),
  186. offset);
  187. *val |= (*(volatile unsigned int *)
  188. PCI_CONFIG_ADDRESS (PCI_BUS (dev), PCI_FUNC (dev),
  189. (offset + 2))) << 16;
  190. _V3CloseConfigWindow ();
  191. return 0;
  192. }
  193. static int pci_integrator_write_byte (struct pci_controller *hose,
  194. pci_dev_t dev, int offset,
  195. unsigned char val)
  196. {
  197. _V3OpenConfigWindow ();
  198. *(volatile unsigned char *) PCI_CONFIG_ADDRESS (PCI_BUS (dev),
  199. PCI_FUNC (dev),
  200. offset) = val;
  201. _V3CloseConfigWindow ();
  202. return 0;
  203. }
  204. static int pci_integrator_write_word (struct pci_controller *hose,
  205. pci_dev_t dev, int offset,
  206. unsigned short val)
  207. {
  208. _V3OpenConfigWindow ();
  209. *(volatile unsigned short *) PCI_CONFIG_ADDRESS (PCI_BUS (dev),
  210. PCI_FUNC (dev),
  211. offset) = val;
  212. _V3CloseConfigWindow ();
  213. return 0;
  214. }
  215. static int pci_integrator_write_dword (struct pci_controller *hose,
  216. pci_dev_t dev, int offset,
  217. unsigned int val)
  218. {
  219. _V3OpenConfigWindow ();
  220. *(volatile unsigned short *) PCI_CONFIG_ADDRESS (PCI_BUS (dev),
  221. PCI_FUNC (dev),
  222. offset) = (val & 0xFFFF);
  223. *(volatile unsigned short *) PCI_CONFIG_ADDRESS (PCI_BUS (dev),
  224. PCI_FUNC (dev),
  225. (offset + 2)) = ((val >> 16) & 0xFFFF);
  226. _V3CloseConfigWindow ();
  227. return 0;
  228. }
  229. /******************************
  230. * PCI initialisation
  231. ******************************/
  232. struct pci_controller integrator_hose = {
  233. #ifndef CONFIG_PCI_PNP
  234. config_table: pci_integrator_config_table,
  235. #endif
  236. };
  237. void pci_init_board (void)
  238. {
  239. volatile int i, j;
  240. struct pci_controller *hose = &integrator_hose;
  241. /* setting this register will take the V3 out of reset */
  242. *(volatile unsigned int *) (INTEGRATOR_SC_PCIENABLE) = 1;
  243. /* wait a few usecs to settle the device and the PCI bus */
  244. for (i = 0; i < 100; i++)
  245. j = i + 1;
  246. /* Now write the Base I/O Address Word to V3_BASE + 0x6C */
  247. *(volatile unsigned short *) (V3_BASE + V3_LB_IO_BASE) =
  248. (unsigned short) (V3_BASE >> 16);
  249. do {
  250. *(volatile unsigned char *) (V3_BASE + V3_MAIL_DATA) = 0xAA;
  251. *(volatile unsigned char *) (V3_BASE + V3_MAIL_DATA + 4) =
  252. 0x55;
  253. } while (*(volatile unsigned char *) (V3_BASE + V3_MAIL_DATA) != 0xAA
  254. || *(volatile unsigned char *) (V3_BASE + V3_MAIL_DATA +
  255. 4) != 0x55);
  256. /* Make sure that V3 register access is not locked, if it is, unlock it */
  257. if ((*(volatile unsigned short *) (V3_BASE + V3_SYSTEM) &
  258. V3_SYSTEM_M_LOCK)
  259. == V3_SYSTEM_M_LOCK)
  260. *(volatile unsigned short *) (V3_BASE + V3_SYSTEM) = 0xA05F;
  261. /* Ensure that the slave accesses from PCI are disabled while we */
  262. /* setup windows */
  263. *(volatile unsigned short *) (V3_BASE + V3_PCI_CMD) &=
  264. ~(V3_COMMAND_M_MEM_EN | V3_COMMAND_M_IO_EN);
  265. /* Clear RST_OUT to 0; keep the PCI bus in reset until we've finished */
  266. *(volatile unsigned short *) (V3_BASE + V3_SYSTEM) &=
  267. ~V3_SYSTEM_M_RST_OUT;
  268. /* Make all accesses from PCI space retry until we're ready for them */
  269. *(volatile unsigned short *) (V3_BASE + V3_PCI_CFG) |=
  270. V3_PCI_CFG_M_RETRY_EN;
  271. /* Set up any V3 PCI Configuration Registers that we absolutely have to */
  272. /* LB_CFG controls Local Bus protocol. */
  273. /* Enable LocalBus byte strobes for READ accesses too. */
  274. /* set bit 7 BE_IMODE and bit 6 BE_OMODE */
  275. *(volatile unsigned short *) (V3_BASE + V3_LB_CFG) |= 0x0C0;
  276. /* PCI_CMD controls overall PCI operation. */
  277. /* Enable PCI bus master. */
  278. *(volatile unsigned short *) (V3_BASE + V3_PCI_CMD) |= 0x04;
  279. /* PCI_MAP0 controls where the PCI to CPU memory window is on Local Bus */
  280. *(volatile unsigned int *) (V3_BASE + V3_PCI_MAP0) =
  281. (INTEGRATOR_BOOT_ROM_BASE) | (V3_PCI_MAP_M_ADR_SIZE_512M |
  282. V3_PCI_MAP_M_REG_EN |
  283. V3_PCI_MAP_M_ENABLE);
  284. /* PCI_BASE0 is the PCI address of the start of the window */
  285. *(volatile unsigned int *) (V3_BASE + V3_PCI_BASE0) =
  286. INTEGRATOR_BOOT_ROM_BASE;
  287. /* PCI_MAP1 is LOCAL address of the start of the window */
  288. *(volatile unsigned int *) (V3_BASE + V3_PCI_MAP1) =
  289. (INTEGRATOR_HDR0_SDRAM_BASE) | (V3_PCI_MAP_M_ADR_SIZE_1024M |
  290. V3_PCI_MAP_M_REG_EN |
  291. V3_PCI_MAP_M_ENABLE);
  292. /* PCI_BASE1 is the PCI address of the start of the window */
  293. *(volatile unsigned int *) (V3_BASE + V3_PCI_BASE1) =
  294. INTEGRATOR_HDR0_SDRAM_BASE;
  295. /* Set up the windows from local bus memory into PCI configuration, */
  296. /* I/O and Memory. */
  297. /* PCI I/O, LB_BASE2 and LB_MAP2 are used exclusively for this. */
  298. *(volatile unsigned short *) (V3_BASE + V3_LB_BASE2) =
  299. ((CPU_PCI_IO_ADRS >> 24) << 8) | V3_LB_BASE_M_ENABLE;
  300. *(volatile unsigned short *) (V3_BASE + V3_LB_MAP2) = 0;
  301. /* PCI Configuration, use LB_BASE1/LB_MAP1. */
  302. /* PCI Memory use LB_BASE0/LB_MAP0 and LB_BASE1/LB_MAP1 */
  303. /* Map first 256Mbytes as non-prefetchable via BASE0/MAP0 */
  304. /* (INTEGRATOR_PCI_BASE == PCI_MEM_BASE) */
  305. *(volatile unsigned int *) (V3_BASE + V3_LB_BASE0) =
  306. INTEGRATOR_PCI_BASE | (0x80 | V3_LB_BASE_M_ENABLE);
  307. *(volatile unsigned short *) (V3_BASE + V3_LB_MAP0) =
  308. ((INTEGRATOR_PCI_BASE >> 20) << 0x4) | 0x0006;
  309. /* Map second 256 Mbytes as prefetchable via BASE1/MAP1 */
  310. *(volatile unsigned int *) (V3_BASE + V3_LB_BASE1) =
  311. INTEGRATOR_PCI_BASE | (0x84 | V3_LB_BASE_M_ENABLE);
  312. *(volatile unsigned short *) (V3_BASE + V3_LB_MAP1) =
  313. (((INTEGRATOR_PCI_BASE + 0x10000000) >> 20) << 4) | 0x0006;
  314. /* Allow accesses to PCI Configuration space */
  315. /* and set up A1, A0 for type 1 config cycles */
  316. *(volatile unsigned short *) (V3_BASE + V3_PCI_CFG) =
  317. ((*(volatile unsigned short *) (V3_BASE + V3_PCI_CFG)) &
  318. ~(V3_PCI_CFG_M_RETRY_EN | V3_PCI_CFG_M_AD_LOW1)) |
  319. V3_PCI_CFG_M_AD_LOW0;
  320. /* now we can allow in PCI MEMORY accesses */
  321. *(volatile unsigned short *) (V3_BASE + V3_PCI_CMD) =
  322. (*(volatile unsigned short *) (V3_BASE + V3_PCI_CMD)) |
  323. V3_COMMAND_M_MEM_EN;
  324. /* Set RST_OUT to take the PCI bus is out of reset, PCI devices can */
  325. /* initialise and lock the V3 system register so that no one else */
  326. /* can play with it */
  327. *(volatile unsigned short *) (V3_BASE + V3_SYSTEM) =
  328. (*(volatile unsigned short *) (V3_BASE + V3_SYSTEM)) |
  329. V3_SYSTEM_M_RST_OUT;
  330. *(volatile unsigned short *) (V3_BASE + V3_SYSTEM) =
  331. (*(volatile unsigned short *) (V3_BASE + V3_SYSTEM)) |
  332. V3_SYSTEM_M_LOCK;
  333. /*
  334. * Register the hose
  335. */
  336. hose->first_busno = 0;
  337. hose->last_busno = 0xff;
  338. /* System memory space */
  339. pci_set_region (hose->regions + 0,
  340. 0x00000000, 0x40000000, 0x01000000,
  341. PCI_REGION_MEM | PCI_REGION_MEMORY);
  342. /* PCI Memory - config space */
  343. pci_set_region (hose->regions + 1,
  344. 0x00000000, 0x62000000, 0x01000000, PCI_REGION_MEM);
  345. /* PCI V3 regs */
  346. pci_set_region (hose->regions + 2,
  347. 0x00000000, 0x61000000, 0x00080000, PCI_REGION_MEM);
  348. /* PCI I/O space */
  349. pci_set_region (hose->regions + 3,
  350. 0x00000000, 0x60000000, 0x00010000, PCI_REGION_IO);
  351. pci_set_ops (hose,
  352. pci_integrator_read_byte,
  353. pci_integrator_read__word,
  354. pci_integrator_read_dword,
  355. pci_integrator_write_byte,
  356. pci_integrator_write_word, pci_integrator_write_dword);
  357. hose->region_count = 4;
  358. pci_register_hose (hose);
  359. pciauto_config_init (hose);
  360. pciauto_config_device (hose, 0);
  361. hose->last_busno = pci_hose_scan (hose);
  362. }
  363. #endif
  364. /******************************
  365. Routine:
  366. Description:
  367. ******************************/
  368. void flash__init (void)
  369. {
  370. }
  371. /*************************************************************
  372. Routine:ether__init
  373. Description: take the Ethernet controller out of reset and wait
  374. for the EEPROM load to complete.
  375. *************************************************************/
  376. void ether__init (void)
  377. {
  378. }
  379. /******************************
  380. Routine:
  381. Description:
  382. ******************************/
  383. int dram_init (void)
  384. {
  385. return 0;
  386. }