integratorap.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  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. ({ \
  99. unsigned int __address, __devicebit; \
  100. unsigned short __mapaddress; \
  101. unsigned int __dev = PCI_DEV(__devfn); /* FIXME to check!! (slot?) */ \
  102. \
  103. if (__bus == 0) { \
  104. /* local bus segment so need a type 0 config cycle */ \
  105. /* build the PCI configuration "address" with one-hot in A31-A11 */ \
  106. __address = PCI_CONFIG_BASE; \
  107. __address |= ((__devfn & 0x07) << 8); \
  108. __address |= __offset & 0xFF; \
  109. __mapaddress = 0x000A; /* 101=>config cycle, 0=>A1=A0=0 */ \
  110. __devicebit = (1 << (__dev + 11)); \
  111. \
  112. if ((__devicebit & 0xFF000000) != 0) { \
  113. /* high order bits are handled by the MAP register */ \
  114. __mapaddress |= (__devicebit >> 16); \
  115. } else { \
  116. /* low order bits handled directly in the address */ \
  117. __address |= __devicebit; \
  118. } \
  119. } else { /* bus !=0 */ \
  120. /* not the local bus segment so need a type 1 config cycle */ \
  121. /* A31-A24 are don't care (so clear to 0) */ \
  122. __mapaddress = 0x000B; /* 101=>config cycle, 1=>A1&A0 from PCI_CFG */ \
  123. __address = PCI_CONFIG_BASE; \
  124. __address |= ((__bus & 0xFF) << 16); /* bits 23..16 = bus number */ \
  125. __address |= ((__dev & 0x1F) << 11); /* bits 15..11 = device number */ \
  126. __address |= ((__devfn & 0x07) << 8); /* bits 10..8 = function number*/ \
  127. __address |= __offset & 0xFF; /* bits 7..0 = register number*/ \
  128. } \
  129. _V3Write16(V3_LB_MAP1, __mapaddress); \
  130. \
  131. __address; \
  132. })
  133. // _V3OpenConfigWindow - open V3 configuration window
  134. #define _V3OpenConfigWindow() \
  135. { \
  136. /* Set up base0 to see all 512Mbytes of memory space (not */ \
  137. /* prefetchable), this frees up base1 for re-use by configuration*/ \
  138. /* memory */ \
  139. \
  140. _V3Write32 (V3_LB_BASE0, ((INTEGRATOR_PCI_BASE & 0xFFF00000) | \
  141. 0x90 | V3_LB_BASE_M_ENABLE)); \
  142. /* Set up base1 to point into configuration space, note that MAP1 */ \
  143. /* register is set up by pciMakeConfigAddress(). */ \
  144. \
  145. _V3Write32 (V3_LB_BASE1, ((CPU_PCI_CNFG_ADRS & 0xFFF00000) | \
  146. 0x40 | V3_LB_BASE_M_ENABLE)); \
  147. }
  148. // _V3CloseConfigWindow - close V3 configuration window
  149. #define _V3CloseConfigWindow() \
  150. { \
  151. /* Reassign base1 for use by prefetchable PCI memory */ \
  152. _V3Write32 (V3_LB_BASE1, (((INTEGRATOR_PCI_BASE + 0x10000000) & 0xFFF00000) \
  153. | 0x84 | V3_LB_BASE_M_ENABLE)); \
  154. _V3Write16 (V3_LB_MAP1, \
  155. (((INTEGRATOR_PCI_BASE + 0x10000000) & 0xFFF00000) >> 16) | 0x0006); \
  156. \
  157. /* And shrink base0 back to a 256M window (NOTE: MAP0 already correct) */ \
  158. \
  159. _V3Write32 (V3_LB_BASE0, ((INTEGRATOR_PCI_BASE & 0xFFF00000) | \
  160. 0x80 | V3_LB_BASE_M_ENABLE)); \
  161. }
  162. static int pci_integrator_read_byte(struct pci_controller *hose, pci_dev_t dev,
  163. int offset, unsigned char *val)
  164. {
  165. _V3OpenConfigWindow();
  166. *val = *(volatile unsigned char *)PCI_CONFIG_ADDRESS(PCI_BUS(dev), PCI_FUNC(dev), offset);
  167. _V3CloseConfigWindow();
  168. return 0;
  169. }
  170. static int pci_integrator_read__word(struct pci_controller *hose, pci_dev_t dev,
  171. int offset, unsigned short *val)
  172. {
  173. _V3OpenConfigWindow();
  174. *val = *(volatile unsigned short *)PCI_CONFIG_ADDRESS(PCI_BUS(dev), PCI_FUNC(dev), offset);
  175. _V3CloseConfigWindow();
  176. return 0;
  177. }
  178. static int pci_integrator_read_dword(struct pci_controller *hose, pci_dev_t dev,
  179. int offset, unsigned int *val)
  180. {
  181. _V3OpenConfigWindow();
  182. *val = *(volatile unsigned short *)PCI_CONFIG_ADDRESS(PCI_BUS(dev), PCI_FUNC(dev), offset);
  183. *val |= (*(volatile unsigned int *)PCI_CONFIG_ADDRESS(PCI_BUS(dev), PCI_FUNC(dev), (offset+2))) << 16;
  184. _V3CloseConfigWindow();
  185. return 0;
  186. }
  187. static int pci_integrator_write_byte(struct pci_controller *hose, pci_dev_t dev,
  188. int offset, unsigned char val)
  189. {
  190. _V3OpenConfigWindow();
  191. *(volatile unsigned char *)PCI_CONFIG_ADDRESS(PCI_BUS(dev), PCI_FUNC(dev), offset) = val;
  192. _V3CloseConfigWindow();
  193. return 0;
  194. }
  195. static int pci_integrator_write_word(struct pci_controller *hose, pci_dev_t dev,
  196. int offset,unsigned short val)
  197. {
  198. _V3OpenConfigWindow();
  199. *(volatile unsigned short *)PCI_CONFIG_ADDRESS(PCI_BUS(dev), PCI_FUNC(dev), offset) = val;
  200. _V3CloseConfigWindow();
  201. return 0;
  202. }
  203. static int pci_integrator_write_dword(struct pci_controller *hose, pci_dev_t dev,
  204. int offset, unsigned int val)
  205. {
  206. _V3OpenConfigWindow();
  207. *(volatile unsigned short *)PCI_CONFIG_ADDRESS(PCI_BUS(dev), PCI_FUNC(dev), offset) = (val & 0xFFFF);
  208. *(volatile unsigned short *)PCI_CONFIG_ADDRESS(PCI_BUS(dev), PCI_FUNC(dev), (offset + 2)) = ((val >> 16) & 0xFFFF);
  209. _V3CloseConfigWindow();
  210. return 0;
  211. }
  212. /******************************
  213. * PCI initialisation
  214. ******************************/
  215. struct pci_controller integrator_hose = {
  216. #ifndef CONFIG_PCI_PNP
  217. config_table: pci_integrator_config_table,
  218. #endif
  219. };
  220. void pci_init_board(void)
  221. {
  222. volatile int i, j;
  223. struct pci_controller *hose = &integrator_hose;
  224. /* setting this register will take the V3 out of reset */
  225. *(volatile unsigned int *)(INTEGRATOR_SC_PCIENABLE) = 1;
  226. /* wait a few usecs to settle the device and the PCI bus */
  227. for (i = 0; i < 100 ; i++)
  228. j = i + 1;
  229. /* Now write the Base I/O Address Word to V3_BASE + 0x6C */
  230. *(volatile unsigned short *)(V3_BASE + V3_LB_IO_BASE) = (unsigned short)(V3_BASE >> 16);
  231. do {
  232. *(volatile unsigned char *)(V3_BASE + V3_MAIL_DATA) = 0xAA;
  233. *(volatile unsigned char *)(V3_BASE + V3_MAIL_DATA + 4) = 0x55;
  234. } while (*(volatile unsigned char *)(V3_BASE + V3_MAIL_DATA) != 0xAA ||
  235. *(volatile unsigned char *)(V3_BASE + V3_MAIL_DATA + 4) != 0x55);
  236. /* Make sure that V3 register access is not locked, if it is, unlock it */
  237. if ((*(volatile unsigned short *)(V3_BASE + V3_SYSTEM) & V3_SYSTEM_M_LOCK)
  238. == V3_SYSTEM_M_LOCK)
  239. *(volatile unsigned short *)(V3_BASE + V3_SYSTEM) = 0xA05F;
  240. /* Ensure that the slave accesses from PCI are disabled while we */
  241. /* setup windows */
  242. *(volatile unsigned short *)(V3_BASE + V3_PCI_CMD) &=
  243. ~(V3_COMMAND_M_MEM_EN | V3_COMMAND_M_IO_EN);
  244. /* Clear RST_OUT to 0; keep the PCI bus in reset until we've finished */
  245. *(volatile unsigned short *)(V3_BASE + V3_SYSTEM) &= ~V3_SYSTEM_M_RST_OUT;
  246. /* Make all accesses from PCI space retry until we're ready for them */
  247. *(volatile unsigned short *)(V3_BASE + V3_PCI_CFG) |= V3_PCI_CFG_M_RETRY_EN;
  248. /* Set up any V3 PCI Configuration Registers that we absolutely have to */
  249. /* LB_CFG controls Local Bus protocol. */
  250. /* Enable LocalBus byte strobes for READ accesses too. */
  251. /* set bit 7 BE_IMODE and bit 6 BE_OMODE */
  252. *(volatile unsigned short *)(V3_BASE + V3_LB_CFG) |= 0x0C0;
  253. /* PCI_CMD controls overall PCI operation. */
  254. /* Enable PCI bus master. */
  255. *(volatile unsigned short *)(V3_BASE + V3_PCI_CMD) |= 0x04;
  256. /* PCI_MAP0 controls where the PCI to CPU memory window is on Local Bus*/
  257. *(volatile unsigned int *)(V3_BASE + V3_PCI_MAP0) = (INTEGRATOR_BOOT_ROM_BASE) |
  258. (V3_PCI_MAP_M_ADR_SIZE_512M |
  259. V3_PCI_MAP_M_REG_EN |
  260. V3_PCI_MAP_M_ENABLE);
  261. /* PCI_BASE0 is the PCI address of the start of the window */
  262. *(volatile unsigned int *)(V3_BASE + V3_PCI_BASE0) = INTEGRATOR_BOOT_ROM_BASE;
  263. /* PCI_MAP1 is LOCAL address of the start of the window */
  264. *(volatile unsigned int *)(V3_BASE + V3_PCI_MAP1) = (INTEGRATOR_HDR0_SDRAM_BASE) |
  265. (V3_PCI_MAP_M_ADR_SIZE_1024M | V3_PCI_MAP_M_REG_EN |
  266. V3_PCI_MAP_M_ENABLE);
  267. /* PCI_BASE1 is the PCI address of the start of the window */
  268. *(volatile unsigned int *)(V3_BASE + V3_PCI_BASE1) = INTEGRATOR_HDR0_SDRAM_BASE;
  269. /* Set up the windows from local bus memory into PCI configuration, */
  270. /* I/O and Memory. */
  271. /* PCI I/O, LB_BASE2 and LB_MAP2 are used exclusively for this. */
  272. *(volatile unsigned short *)(V3_BASE +V3_LB_BASE2) =
  273. ((CPU_PCI_IO_ADRS >> 24) << 8) | V3_LB_BASE_M_ENABLE;
  274. *(volatile unsigned short *)(V3_BASE + V3_LB_MAP2) = 0;
  275. /* PCI Configuration, use LB_BASE1/LB_MAP1. */
  276. /* PCI Memory use LB_BASE0/LB_MAP0 and LB_BASE1/LB_MAP1 */
  277. /* Map first 256Mbytes as non-prefetchable via BASE0/MAP0 */
  278. /* (INTEGRATOR_PCI_BASE == PCI_MEM_BASE) */
  279. *(volatile unsigned int *)(V3_BASE + V3_LB_BASE0) =
  280. INTEGRATOR_PCI_BASE | (0x80 | V3_LB_BASE_M_ENABLE);
  281. *(volatile unsigned short *)(V3_BASE + V3_LB_MAP0) =
  282. ((INTEGRATOR_PCI_BASE >> 20) << 0x4) | 0x0006;
  283. /* Map second 256 Mbytes as prefetchable via BASE1/MAP1 */
  284. *(volatile unsigned int *)(V3_BASE + V3_LB_BASE1) =
  285. INTEGRATOR_PCI_BASE | (0x84 | V3_LB_BASE_M_ENABLE);
  286. *(volatile unsigned short *)(V3_BASE + V3_LB_MAP1) =
  287. (((INTEGRATOR_PCI_BASE + 0x10000000) >> 20) << 4) | 0x0006;
  288. /* Allow accesses to PCI Configuration space */
  289. /* and set up A1, A0 for type 1 config cycles */
  290. *(volatile unsigned short *)(V3_BASE + V3_PCI_CFG) =
  291. ((*(volatile unsigned short *)(V3_BASE + V3_PCI_CFG)) &
  292. ~(V3_PCI_CFG_M_RETRY_EN | V3_PCI_CFG_M_AD_LOW1) ) |
  293. V3_PCI_CFG_M_AD_LOW0;
  294. /* now we can allow in PCI MEMORY accesses */
  295. *(volatile unsigned short *)(V3_BASE + V3_PCI_CMD) =
  296. (*(volatile unsigned short *)(V3_BASE + V3_PCI_CMD)) | V3_COMMAND_M_MEM_EN;
  297. /* Set RST_OUT to take the PCI bus is out of reset, PCI devices can */
  298. /* initialise and lock the V3 system register so that no one else */
  299. /* can play with it */
  300. *(volatile unsigned short *)(V3_BASE + V3_SYSTEM) =
  301. (*(volatile unsigned short *)(V3_BASE + V3_SYSTEM)) | V3_SYSTEM_M_RST_OUT;
  302. *(volatile unsigned short *)(V3_BASE + V3_SYSTEM) =
  303. (*(volatile unsigned short *)(V3_BASE + V3_SYSTEM)) | V3_SYSTEM_M_LOCK;
  304. /*
  305. * Register the hose
  306. */
  307. hose->first_busno = 0;
  308. hose->last_busno = 0xff;
  309. /* System memory space */
  310. pci_set_region(hose->regions + 0,
  311. 0x00000000, 0x40000000, 0x01000000,
  312. PCI_REGION_MEM | PCI_REGION_MEMORY);
  313. /* PCI Memory - config space */
  314. pci_set_region(hose->regions + 1,
  315. 0x00000000, 0x62000000, 0x01000000,
  316. PCI_REGION_MEM);
  317. /* PCI V3 regs */
  318. pci_set_region(hose->regions + 2,
  319. 0x00000000, 0x61000000, 0x00080000,
  320. PCI_REGION_MEM);
  321. /* PCI I/O space */
  322. pci_set_region(hose->regions + 3,
  323. 0x00000000, 0x60000000, 0x00010000,
  324. PCI_REGION_IO);
  325. pci_set_ops(hose,
  326. pci_integrator_read_byte,
  327. pci_integrator_read__word,
  328. pci_integrator_read_dword,
  329. pci_integrator_write_byte,
  330. pci_integrator_write_word,
  331. pci_integrator_write_dword);
  332. hose->region_count = 4;
  333. pci_register_hose(hose);
  334. pciauto_config_init(hose);
  335. pciauto_config_device(hose, 0);
  336. hose->last_busno = pci_hose_scan(hose);
  337. }
  338. #endif
  339. /******************************
  340. Routine:
  341. Description:
  342. ******************************/
  343. void flash__init (void)
  344. {
  345. }
  346. /*************************************************************
  347. Routine:ether__init
  348. Description: take the Ethernet controller out of reset and wait
  349. for the EEPROM load to complete.
  350. *************************************************************/
  351. void ether__init (void)
  352. {
  353. }
  354. /******************************
  355. Routine:
  356. Description:
  357. ******************************/
  358. int dram_init (void)
  359. {
  360. return 0;
  361. }