bamboo.c 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090
  1. /*
  2. * (C) Copyright 2005
  3. * Stefan Roese, DENX Software Engineering, sr@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <asm/processor.h>
  25. #include <asm/gpio.h>
  26. #include <spd_sdram.h>
  27. #include <ppc440.h>
  28. #include "bamboo.h"
  29. void ext_bus_cntlr_init(void);
  30. void configure_ppc440ep_pins(void);
  31. int is_nand_selected(void);
  32. unsigned char cfg_simulate_spd_eeprom[128];
  33. gpio_param_s gpio_tab[GPIO_GROUP_MAX][GPIO_MAX];
  34. #if 0
  35. { /* GPIO Alternate1 Alternate2 Alternate3 */
  36. {
  37. /* GPIO Core 0 */
  38. { GPIO0_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO0_0 -> EBC_ADDR(7) DMA_REQ(2) */
  39. { GPIO0_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO0_1 -> EBC_ADDR(6) DMA_ACK(2) */
  40. { GPIO0_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO0_2 -> EBC_ADDR(5) DMA_EOT/TC(2) */
  41. { GPIO0_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO0_3 -> EBC_ADDR(4) DMA_REQ(3) */
  42. { GPIO0_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO0_4 -> EBC_ADDR(3) DMA_ACK(3) */
  43. { GPIO0_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO0_5 ................. */
  44. { GPIO0_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO0_6 -> EBC_CS_N(1) */
  45. { GPIO0_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO0_7 -> EBC_CS_N(2) */
  46. { GPIO0_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO0_8 -> EBC_CS_N(3) */
  47. { GPIO0_BASE, GPIO_DIS, GPIO_ALT1 }, /* GPIO0_9 -> EBC_CS_N(4) */
  48. { GPIO0_BASE, GPIO_OUT, GPIO_ALT1 }, /* GPIO0_10 -> EBC_CS_N(5) */
  49. { GPIO0_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO0_11 -> EBC_BUS_ERR */
  50. { GPIO0_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO0_12 -> ZII_p0Rxd(0) */
  51. { GPIO0_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO0_13 -> ZII_p0Rxd(1) */
  52. { GPIO0_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO0_14 -> ZII_p0Rxd(2) */
  53. { GPIO0_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO0_15 -> ZII_p0Rxd(3) */
  54. { GPIO0_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO0_16 -> ZII_p0Txd(0) */
  55. { GPIO0_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO0_17 -> ZII_p0Txd(1) */
  56. { GPIO0_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO0_18 -> ZII_p0Txd(2) */
  57. { GPIO0_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO0_19 -> ZII_p0Txd(3) */
  58. { GPIO0_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO0_20 -> ZII_p0Rx_er */
  59. { GPIO0_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO0_21 -> ZII_p0Rx_dv */
  60. { GPIO0_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO0_22 -> ZII_p0RxCrs */
  61. { GPIO0_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO0_23 -> ZII_p0Tx_er */
  62. { GPIO0_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO0_24 -> ZII_p0Tx_en */
  63. { GPIO0_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO0_25 -> ZII_p0Col */
  64. { GPIO0_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO0_26 -> USB2D_RXVALID */
  65. { GPIO0_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO0_27 -> EXT_EBC_REQ USB2D_RXERROR */
  66. { GPIO0_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO0_28 -> USB2D_TXVALID */
  67. { GPIO0_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO0_29 -> EBC_EXT_HDLA USB2D_PAD_SUSPNDM */
  68. { GPIO0_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO0_30 -> EBC_EXT_ACK USB2D_XCVRSELECT */
  69. { GPIO0_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO0_31 -> EBC_EXR_BUSREQ USB2D_TERMSELECT */
  70. },
  71. {
  72. /* GPIO Core 1 */
  73. { GPIO1_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO1_0 -> USB2D_OPMODE0 */
  74. { GPIO1_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO1_1 -> USB2D_OPMODE1 */
  75. { GPIO1_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO1_2 -> UART0_DCD_N UART1_DSR_CTS_N UART2_SOUT */
  76. { GPIO1_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO1_3 -> UART0_8PIN_DSR_N UART1_RTS_DTR_N UART2_SIN */
  77. { GPIO1_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO1_4 -> UART0_8PIN_CTS_N UART3_SIN */
  78. { GPIO1_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO1_5 -> UART0_RTS_N */
  79. { GPIO1_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO1_6 -> UART0_DTR_N UART1_SOUT */
  80. { GPIO1_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO1_7 -> UART0_RI_N UART1_SIN */
  81. { GPIO1_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO1_8 -> UIC_IRQ(0) */
  82. { GPIO1_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO1_9 -> UIC_IRQ(1) */
  83. { GPIO1_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO1_10 -> UIC_IRQ(2) */
  84. { GPIO1_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO1_11 -> UIC_IRQ(3) */
  85. { GPIO1_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO1_12 -> UIC_IRQ(4) DMA_ACK(1) */
  86. { GPIO1_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO1_13 -> UIC_IRQ(6) DMA_EOT/TC(1) */
  87. { GPIO1_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO1_14 -> UIC_IRQ(7) DMA_REQ(0) */
  88. { GPIO1_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO1_15 -> UIC_IRQ(8) DMA_ACK(0) */
  89. { GPIO1_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO1_16 -> UIC_IRQ(9) DMA_EOT/TC(0) */
  90. { GPIO1_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO1_17 -> - */
  91. { GPIO1_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO1_18 -> | */
  92. { GPIO1_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO1_19 -> | */
  93. { GPIO1_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO1_20 -> | */
  94. { GPIO1_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO1_21 -> | */
  95. { GPIO1_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO1_22 -> | */
  96. { GPIO1_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO1_23 -> \ Can be unselected thru TraceSelect Bit */
  97. { GPIO1_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO1_24 -> / in PowerPC440EP Chip */
  98. { GPIO1_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO1_25 -> | */
  99. { GPIO1_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO1_26 -> | */
  100. { GPIO1_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO1_27 -> | */
  101. { GPIO1_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO1_28 -> | */
  102. { GPIO1_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO1_29 -> | */
  103. { GPIO1_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO1_30 -> | */
  104. { GPIO1_BASE, GPIO_DIS, GPIO_SEL }, /* GPIO1_31 -> - */
  105. }
  106. };
  107. #endif
  108. /*----------------------------------------------------------------------------+
  109. | EBC Devices Characteristics
  110. | Peripheral Bank Access Parameters - EBC0_BnAP
  111. | Peripheral Bank Configuration Register - EBC0_BnCR
  112. +----------------------------------------------------------------------------*/
  113. /* Small Flash */
  114. #define EBC0_BNAP_SMALL_FLASH \
  115. EBC0_BNAP_BME_DISABLED | \
  116. EBC0_BNAP_TWT_ENCODE(6) | \
  117. EBC0_BNAP_CSN_ENCODE(0) | \
  118. EBC0_BNAP_OEN_ENCODE(1) | \
  119. EBC0_BNAP_WBN_ENCODE(1) | \
  120. EBC0_BNAP_WBF_ENCODE(3) | \
  121. EBC0_BNAP_TH_ENCODE(1) | \
  122. EBC0_BNAP_RE_ENABLED | \
  123. EBC0_BNAP_SOR_DELAYED | \
  124. EBC0_BNAP_BEM_WRITEONLY | \
  125. EBC0_BNAP_PEN_DISABLED
  126. #define EBC0_BNCR_SMALL_FLASH_CS0 \
  127. EBC0_BNCR_BAS_ENCODE(0xFFF00000) | \
  128. EBC0_BNCR_BS_1MB | \
  129. EBC0_BNCR_BU_RW | \
  130. EBC0_BNCR_BW_8BIT
  131. #define EBC0_BNCR_SMALL_FLASH_CS4 \
  132. EBC0_BNCR_BAS_ENCODE(0x87F00000) | \
  133. EBC0_BNCR_BS_1MB | \
  134. EBC0_BNCR_BU_RW | \
  135. EBC0_BNCR_BW_8BIT
  136. /* Large Flash or SRAM */
  137. #define EBC0_BNAP_LARGE_FLASH_OR_SRAM \
  138. EBC0_BNAP_BME_DISABLED | \
  139. EBC0_BNAP_TWT_ENCODE(8) | \
  140. EBC0_BNAP_CSN_ENCODE(0) | \
  141. EBC0_BNAP_OEN_ENCODE(1) | \
  142. EBC0_BNAP_WBN_ENCODE(1) | \
  143. EBC0_BNAP_WBF_ENCODE(1) | \
  144. EBC0_BNAP_TH_ENCODE(2) | \
  145. EBC0_BNAP_SOR_DELAYED | \
  146. EBC0_BNAP_BEM_RW | \
  147. EBC0_BNAP_PEN_DISABLED
  148. #define EBC0_BNCR_LARGE_FLASH_OR_SRAM_CS0 \
  149. EBC0_BNCR_BAS_ENCODE(0xFF800000) | \
  150. EBC0_BNCR_BS_8MB | \
  151. EBC0_BNCR_BU_RW | \
  152. EBC0_BNCR_BW_16BIT
  153. #define EBC0_BNCR_LARGE_FLASH_OR_SRAM_CS4 \
  154. EBC0_BNCR_BAS_ENCODE(0x87800000) | \
  155. EBC0_BNCR_BS_8MB | \
  156. EBC0_BNCR_BU_RW | \
  157. EBC0_BNCR_BW_16BIT
  158. /* NVRAM - FPGA */
  159. #define EBC0_BNAP_NVRAM_FPGA \
  160. EBC0_BNAP_BME_DISABLED | \
  161. EBC0_BNAP_TWT_ENCODE(9) | \
  162. EBC0_BNAP_CSN_ENCODE(0) | \
  163. EBC0_BNAP_OEN_ENCODE(1) | \
  164. EBC0_BNAP_WBN_ENCODE(1) | \
  165. EBC0_BNAP_WBF_ENCODE(0) | \
  166. EBC0_BNAP_TH_ENCODE(2) | \
  167. EBC0_BNAP_RE_ENABLED | \
  168. EBC0_BNAP_SOR_DELAYED | \
  169. EBC0_BNAP_BEM_WRITEONLY | \
  170. EBC0_BNAP_PEN_DISABLED
  171. #define EBC0_BNCR_NVRAM_FPGA_CS5 \
  172. EBC0_BNCR_BAS_ENCODE(0x80000000) | \
  173. EBC0_BNCR_BS_1MB | \
  174. EBC0_BNCR_BU_RW | \
  175. EBC0_BNCR_BW_8BIT
  176. /* Nand Flash */
  177. #define EBC0_BNAP_NAND_FLASH \
  178. EBC0_BNAP_BME_DISABLED | \
  179. EBC0_BNAP_TWT_ENCODE(3) | \
  180. EBC0_BNAP_CSN_ENCODE(0) | \
  181. EBC0_BNAP_OEN_ENCODE(0) | \
  182. EBC0_BNAP_WBN_ENCODE(0) | \
  183. EBC0_BNAP_WBF_ENCODE(0) | \
  184. EBC0_BNAP_TH_ENCODE(1) | \
  185. EBC0_BNAP_RE_ENABLED | \
  186. EBC0_BNAP_SOR_NOT_DELAYED | \
  187. EBC0_BNAP_BEM_RW | \
  188. EBC0_BNAP_PEN_DISABLED
  189. #define EBC0_BNCR_NAND_FLASH_CS0 0xB8400000
  190. /* NAND0 */
  191. #define EBC0_BNCR_NAND_FLASH_CS1 \
  192. EBC0_BNCR_BAS_ENCODE(0x90000000) | \
  193. EBC0_BNCR_BS_1MB | \
  194. EBC0_BNCR_BU_RW | \
  195. EBC0_BNCR_BW_32BIT
  196. /* NAND1 - Bank2 */
  197. #define EBC0_BNCR_NAND_FLASH_CS2 \
  198. EBC0_BNCR_BAS_ENCODE(0x94000000) | \
  199. EBC0_BNCR_BS_1MB | \
  200. EBC0_BNCR_BU_RW | \
  201. EBC0_BNCR_BW_32BIT
  202. /* NAND1 - Bank3 */
  203. #define EBC0_BNCR_NAND_FLASH_CS3 \
  204. EBC0_BNCR_BAS_ENCODE(0x94000000) | \
  205. EBC0_BNCR_BS_1MB | \
  206. EBC0_BNCR_BU_RW | \
  207. EBC0_BNCR_BW_32BIT
  208. int board_early_init_f(void)
  209. {
  210. ext_bus_cntlr_init();
  211. /*--------------------------------------------------------------------
  212. * Setup the interrupt controller polarities, triggers, etc.
  213. *-------------------------------------------------------------------*/
  214. mtdcr(uic0sr, 0xffffffff); /* clear all */
  215. mtdcr(uic0er, 0x00000000); /* disable all */
  216. mtdcr(uic0cr, 0x00000009); /* ATI & UIC1 crit are critical */
  217. mtdcr(uic0pr, 0xfffffe13); /* per ref-board manual */
  218. mtdcr(uic0tr, 0x01c00008); /* per ref-board manual */
  219. mtdcr(uic0vr, 0x00000001); /* int31 highest, base=0x000 */
  220. mtdcr(uic0sr, 0xffffffff); /* clear all */
  221. mtdcr(uic1sr, 0xffffffff); /* clear all */
  222. mtdcr(uic1er, 0x00000000); /* disable all */
  223. mtdcr(uic1cr, 0x00000000); /* all non-critical */
  224. mtdcr(uic1pr, 0xffffe0ff); /* per ref-board manual */
  225. mtdcr(uic1tr, 0x00ffc000); /* per ref-board manual */
  226. mtdcr(uic1vr, 0x00000001); /* int31 highest, base=0x000 */
  227. mtdcr(uic1sr, 0xffffffff); /* clear all */
  228. /*--------------------------------------------------------------------
  229. * Setup the GPIO pins
  230. *-------------------------------------------------------------------*/
  231. out32(GPIO0_OSRL, 0x00000400);
  232. out32(GPIO0_OSRH, 0x00000000);
  233. out32(GPIO0_TSRL, 0x00000400);
  234. out32(GPIO0_TSRH, 0x00000000);
  235. out32(GPIO0_ISR1L, 0x00000000);
  236. out32(GPIO0_ISR1H, 0x00000000);
  237. out32(GPIO0_ISR2L, 0x00000000);
  238. out32(GPIO0_ISR2H, 0x00000000);
  239. out32(GPIO0_ISR3L, 0x00000000);
  240. out32(GPIO0_ISR3H, 0x00000000);
  241. out32(GPIO1_OSRL, 0x0C380000);
  242. out32(GPIO1_OSRH, 0x00000000);
  243. out32(GPIO1_TSRL, 0x0C380000);
  244. out32(GPIO1_TSRH, 0x00000000);
  245. out32(GPIO1_ISR1L, 0x0FC30000);
  246. out32(GPIO1_ISR1H, 0x00000000);
  247. out32(GPIO1_ISR2L, 0x0C010000);
  248. out32(GPIO1_ISR2H, 0x00000000);
  249. out32(GPIO1_ISR3L, 0x01400000);
  250. out32(GPIO1_ISR3H, 0x00000000);
  251. configure_ppc440ep_pins();
  252. return 0;
  253. }
  254. #if (CONFIG_COMMANDS & CFG_CMD_NAND)
  255. #include <linux/mtd/nand_legacy.h>
  256. extern struct nand_chip nand_dev_desc[CFG_MAX_NAND_DEVICE];
  257. /*----------------------------------------------------------------------------+
  258. | nand_reset.
  259. | Reset Nand flash
  260. | This routine will abort previous cmd
  261. +----------------------------------------------------------------------------*/
  262. int nand_reset(ulong addr)
  263. {
  264. int wait=0, stat=0;
  265. out8(addr + NAND_CMD_REG, NAND0_CMD_RESET);
  266. out8(addr + NAND_CMD_REG, NAND0_CMD_READ_STATUS);
  267. while ((stat != 0xc0) && (wait != 0xffff)) {
  268. stat = in8(addr + NAND_DATA_REG);
  269. wait++;
  270. }
  271. if (stat == 0xc0) {
  272. return 0;
  273. } else {
  274. printf("NAND Reset timeout.\n");
  275. return -1;
  276. }
  277. }
  278. void board_nand_set_device(int cs, ulong addr)
  279. {
  280. /* Set NandFlash Core Configuration Register */
  281. out32(addr + NAND_CCR_REG, 0x00001000 | (cs << 24));
  282. switch (cs) {
  283. case 1:
  284. /* -------
  285. * NAND0
  286. * -------
  287. * K9F1208U0A : 4 addr cyc, 1 col + 3 Row
  288. * Set NDF1CR - Enable External CS1 in NAND FLASH controller
  289. */
  290. out32(addr + NAND_CR1_REG, 0x80002222);
  291. break;
  292. case 2:
  293. /* -------
  294. * NAND1
  295. * -------
  296. * K9K2G0B : 5 addr cyc, 2 col + 3 Row
  297. * Set NDF2CR : Enable External CS2 in NAND FLASH controller
  298. */
  299. out32(addr + NAND_CR2_REG, 0xC0007777);
  300. break;
  301. }
  302. /* Perform Reset Command */
  303. if (nand_reset(addr) != 0)
  304. return;
  305. }
  306. void nand_init(void)
  307. {
  308. board_nand_set_device(1, CFG_NAND_ADDR);
  309. nand_probe(CFG_NAND_ADDR);
  310. if (nand_dev_desc[0].ChipID != NAND_ChipID_UNKNOWN) {
  311. print_size(nand_dev_desc[0].totlen, "\n");
  312. }
  313. #if 0 /* NAND1 not supported yet */
  314. board_nand_set_device(2, CFG_NAND2_ADDR);
  315. nand_probe(CFG_NAND2_ADDR);
  316. if (nand_dev_desc[0].ChipID != NAND_ChipID_UNKNOWN) {
  317. print_size(nand_dev_desc[0].totlen, "\n");
  318. }
  319. #endif
  320. }
  321. #endif /* (CONFIG_COMMANDS & CFG_CMD_NAND) */
  322. int checkboard(void)
  323. {
  324. char *s = getenv("serial#");
  325. printf("Board: Bamboo - AMCC PPC440EP Evaluation Board");
  326. if (s != NULL) {
  327. puts(", serial# ");
  328. puts(s);
  329. }
  330. putc('\n');
  331. return (0);
  332. }
  333. /*************************************************************************
  334. *
  335. * init_spd_array -- Bamboo has one bank onboard sdram (plus DIMM)
  336. *
  337. * Fixed memory is composed of :
  338. * MT46V16M16TG-75 from Micron (x 2), 256Mb, 16 M x16, DDR266,
  339. * 13 row add bits, 10 column add bits (but 12 row used only).
  340. * ECC device: MT46V16M8TG-75 from Micron (x 1), 128Mb, x8, DDR266,
  341. * 12 row add bits, 10 column add bits.
  342. * Prepare a subset (only the used ones) of SPD data
  343. *
  344. * Note : if the ECC is enabled (SDRAM_ECC_ENABLE) the size of
  345. * the corresponding bank is divided by 2 due to number of Row addresses
  346. * 12 in the ECC module
  347. *
  348. * Assumes: 64 MB, ECC, non-registered
  349. * PLB @ 133 MHz
  350. *
  351. ************************************************************************/
  352. static void init_spd_array(void)
  353. {
  354. cfg_simulate_spd_eeprom[8] = 0x04; /* 2.5 Volt */
  355. cfg_simulate_spd_eeprom[2] = 0x07; /* DDR ram */
  356. #ifdef CONFIG_DDR_ECC
  357. cfg_simulate_spd_eeprom[11] = 0x02; /* ECC ON : 02 OFF : 00 */
  358. cfg_simulate_spd_eeprom[31] = 0x08; /* bankSizeID: 32MB */
  359. cfg_simulate_spd_eeprom[3] = 0x0C; /* num Row Addr: 12 */
  360. #else
  361. cfg_simulate_spd_eeprom[11] = 0x00; /* ECC ON : 02 OFF : 00 */
  362. cfg_simulate_spd_eeprom[31] = 0x10; /* bankSizeID: 64MB */
  363. cfg_simulate_spd_eeprom[3] = 0x0D; /* num Row Addr: 13 */
  364. #endif
  365. cfg_simulate_spd_eeprom[4] = 0x09; /* numColAddr: 9 */
  366. cfg_simulate_spd_eeprom[5] = 0x01; /* numBanks: 1 */
  367. cfg_simulate_spd_eeprom[0] = 0x80; /* number of SPD bytes used: 128 */
  368. cfg_simulate_spd_eeprom[1] = 0x08; /* total number bytes in SPD device = 256 */
  369. cfg_simulate_spd_eeprom[21] = 0x00; /* not registered: 0 registered : 0x02*/
  370. cfg_simulate_spd_eeprom[6] = 0x20; /* Module data width: 32 bits */
  371. cfg_simulate_spd_eeprom[7] = 0x00; /* Module data width continued: +0 */
  372. cfg_simulate_spd_eeprom[15] = 0x01; /* wcsbc = 1 */
  373. cfg_simulate_spd_eeprom[27] = 0x50; /* tRpNs = 20 ns */
  374. cfg_simulate_spd_eeprom[29] = 0x50; /* tRcdNs = 20 ns */
  375. cfg_simulate_spd_eeprom[30] = 45; /* tRasNs */
  376. cfg_simulate_spd_eeprom[18] = 0x0C; /* casBit (2,2.5) */
  377. cfg_simulate_spd_eeprom[9] = 0x75; /* SDRAM Cycle Time (cas latency 2.5) = 7.5 ns */
  378. cfg_simulate_spd_eeprom[23] = 0xA0; /* SDRAM Cycle Time (cas latency 2) = 10 ns */
  379. cfg_simulate_spd_eeprom[25] = 0x00; /* SDRAM Cycle Time (cas latency 1.5) = N.A */
  380. cfg_simulate_spd_eeprom[12] = 0x82; /* refresh Rate Type: Normal (15.625us) + Self refresh */
  381. }
  382. long int initdram (int board_type)
  383. {
  384. long dram_size = 0;
  385. /*
  386. * First write simulated values in eeprom array for onboard bank 0
  387. */
  388. init_spd_array();
  389. dram_size = spd_sdram();
  390. return dram_size;
  391. }
  392. #if defined(CFG_DRAM_TEST)
  393. int testdram(void)
  394. {
  395. unsigned long *mem = (unsigned long *)0;
  396. const unsigned long kend = (1024 / sizeof(unsigned long));
  397. unsigned long k, n;
  398. mtmsr(0);
  399. for (k = 0; k < CFG_KBYTES_SDRAM;
  400. ++k, mem += (1024 / sizeof(unsigned long))) {
  401. if ((k & 1023) == 0) {
  402. printf("%3d MB\r", k / 1024);
  403. }
  404. memset(mem, 0xaaaaaaaa, 1024);
  405. for (n = 0; n < kend; ++n) {
  406. if (mem[n] != 0xaaaaaaaa) {
  407. printf("SDRAM test fails at: %08x\n",
  408. (uint) & mem[n]);
  409. return 1;
  410. }
  411. }
  412. memset(mem, 0x55555555, 1024);
  413. for (n = 0; n < kend; ++n) {
  414. if (mem[n] != 0x55555555) {
  415. printf("SDRAM test fails at: %08x\n",
  416. (uint) & mem[n]);
  417. return 1;
  418. }
  419. }
  420. }
  421. printf("SDRAM test passes\n");
  422. return 0;
  423. }
  424. #endif
  425. /*************************************************************************
  426. * pci_pre_init
  427. *
  428. * This routine is called just prior to registering the hose and gives
  429. * the board the opportunity to check things. Returning a value of zero
  430. * indicates that things are bad & PCI initialization should be aborted.
  431. *
  432. * Different boards may wish to customize the pci controller structure
  433. * (add regions, override default access routines, etc) or perform
  434. * certain pre-initialization actions.
  435. *
  436. ************************************************************************/
  437. #if defined(CONFIG_PCI) && defined(CFG_PCI_PRE_INIT)
  438. int pci_pre_init(struct pci_controller *hose)
  439. {
  440. unsigned long addr;
  441. /*-------------------------------------------------------------------------+
  442. | Set priority for all PLB3 devices to 0.
  443. | Set PLB3 arbiter to fair mode.
  444. +-------------------------------------------------------------------------*/
  445. mfsdr(sdr_amp1, addr);
  446. mtsdr(sdr_amp1, (addr & 0x000000FF) | 0x0000FF00);
  447. addr = mfdcr(plb3_acr);
  448. mtdcr(plb3_acr, addr | 0x80000000);
  449. /*-------------------------------------------------------------------------+
  450. | Set priority for all PLB4 devices to 0.
  451. +-------------------------------------------------------------------------*/
  452. mfsdr(sdr_amp0, addr);
  453. mtsdr(sdr_amp0, (addr & 0x000000FF) | 0x0000FF00);
  454. addr = mfdcr(plb4_acr) | 0xa0000000; /* Was 0x8---- */
  455. mtdcr(plb4_acr, addr);
  456. /*-------------------------------------------------------------------------+
  457. | Set Nebula PLB4 arbiter to fair mode.
  458. +-------------------------------------------------------------------------*/
  459. /* Segment0 */
  460. addr = (mfdcr(plb0_acr) & ~plb0_acr_ppm_mask) | plb0_acr_ppm_fair;
  461. addr = (addr & ~plb0_acr_hbu_mask) | plb0_acr_hbu_enabled;
  462. addr = (addr & ~plb0_acr_rdp_mask) | plb0_acr_rdp_4deep;
  463. addr = (addr & ~plb0_acr_wrp_mask) | plb0_acr_wrp_2deep;
  464. mtdcr(plb0_acr, addr);
  465. /* Segment1 */
  466. addr = (mfdcr(plb1_acr) & ~plb1_acr_ppm_mask) | plb1_acr_ppm_fair;
  467. addr = (addr & ~plb1_acr_hbu_mask) | plb1_acr_hbu_enabled;
  468. addr = (addr & ~plb1_acr_rdp_mask) | plb1_acr_rdp_4deep;
  469. addr = (addr & ~plb1_acr_wrp_mask) | plb1_acr_wrp_2deep;
  470. mtdcr(plb1_acr, addr);
  471. return 1;
  472. }
  473. #endif /* defined(CONFIG_PCI) && defined(CFG_PCI_PRE_INIT) */
  474. /*************************************************************************
  475. * pci_target_init
  476. *
  477. * The bootstrap configuration provides default settings for the pci
  478. * inbound map (PIM). But the bootstrap config choices are limited and
  479. * may not be sufficient for a given board.
  480. *
  481. ************************************************************************/
  482. #if defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT)
  483. void pci_target_init(struct pci_controller *hose)
  484. {
  485. /*--------------------------------------------------------------------------+
  486. * Set up Direct MMIO registers
  487. *--------------------------------------------------------------------------*/
  488. /*--------------------------------------------------------------------------+
  489. | PowerPC440 EP PCI Master configuration.
  490. | Map one 1Gig range of PLB/processor addresses to PCI memory space.
  491. | PLB address 0xA0000000-0xDFFFFFFF ==> PCI address 0xA0000000-0xDFFFFFFF
  492. | Use byte reversed out routines to handle endianess.
  493. | Make this region non-prefetchable.
  494. +--------------------------------------------------------------------------*/
  495. out32r(PCIX0_PMM0MA, 0x00000000); /* PMM0 Mask/Attribute - disabled b4 setting */
  496. out32r(PCIX0_PMM0LA, CFG_PCI_MEMBASE); /* PMM0 Local Address */
  497. out32r(PCIX0_PMM0PCILA, CFG_PCI_MEMBASE); /* PMM0 PCI Low Address */
  498. out32r(PCIX0_PMM0PCIHA, 0x00000000); /* PMM0 PCI High Address */
  499. out32r(PCIX0_PMM0MA, 0xE0000001); /* 512M + No prefetching, and enable region */
  500. out32r(PCIX0_PMM1MA, 0x00000000); /* PMM0 Mask/Attribute - disabled b4 setting */
  501. out32r(PCIX0_PMM1LA, CFG_PCI_MEMBASE2); /* PMM0 Local Address */
  502. out32r(PCIX0_PMM1PCILA, CFG_PCI_MEMBASE2); /* PMM0 PCI Low Address */
  503. out32r(PCIX0_PMM1PCIHA, 0x00000000); /* PMM0 PCI High Address */
  504. out32r(PCIX0_PMM1MA, 0xE0000001); /* 512M + No prefetching, and enable region */
  505. out32r(PCIX0_PTM1MS, 0x00000001); /* Memory Size/Attribute */
  506. out32r(PCIX0_PTM1LA, 0); /* Local Addr. Reg */
  507. out32r(PCIX0_PTM2MS, 0); /* Memory Size/Attribute */
  508. out32r(PCIX0_PTM2LA, 0); /* Local Addr. Reg */
  509. /*--------------------------------------------------------------------------+
  510. * Set up Configuration registers
  511. *--------------------------------------------------------------------------*/
  512. /* Program the board's subsystem id/vendor id */
  513. pci_write_config_word(0, PCI_SUBSYSTEM_VENDOR_ID,
  514. CFG_PCI_SUBSYS_VENDORID);
  515. pci_write_config_word(0, PCI_SUBSYSTEM_ID, CFG_PCI_SUBSYS_ID);
  516. /* Configure command register as bus master */
  517. pci_write_config_word(0, PCI_COMMAND, PCI_COMMAND_MASTER);
  518. /* 240nS PCI clock */
  519. pci_write_config_word(0, PCI_LATENCY_TIMER, 1);
  520. /* No error reporting */
  521. pci_write_config_word(0, PCI_ERREN, 0);
  522. pci_write_config_dword(0, PCI_BRDGOPT2, 0x00000101);
  523. }
  524. #endif /* defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT) */
  525. /*************************************************************************
  526. * pci_master_init
  527. *
  528. ************************************************************************/
  529. #if defined(CONFIG_PCI) && defined(CFG_PCI_MASTER_INIT)
  530. void pci_master_init(struct pci_controller *hose)
  531. {
  532. unsigned short temp_short;
  533. /*--------------------------------------------------------------------------+
  534. | Write the PowerPC440 EP PCI Configuration regs.
  535. | Enable PowerPC440 EP to be a master on the PCI bus (PMM).
  536. | Enable PowerPC440 EP to act as a PCI memory target (PTM).
  537. +--------------------------------------------------------------------------*/
  538. pci_read_config_word(0, PCI_COMMAND, &temp_short);
  539. pci_write_config_word(0, PCI_COMMAND,
  540. temp_short | PCI_COMMAND_MASTER |
  541. PCI_COMMAND_MEMORY);
  542. }
  543. #endif /* defined(CONFIG_PCI) && defined(CFG_PCI_MASTER_INIT) */
  544. /*************************************************************************
  545. * is_pci_host
  546. *
  547. * This routine is called to determine if a pci scan should be
  548. * performed. With various hardware environments (especially cPCI and
  549. * PPMC) it's insufficient to depend on the state of the arbiter enable
  550. * bit in the strap register, or generic host/adapter assumptions.
  551. *
  552. * Rather than hard-code a bad assumption in the general 440 code, the
  553. * 440 pci code requires the board to decide at runtime.
  554. *
  555. * Return 0 for adapter mode, non-zero for host (monarch) mode.
  556. *
  557. *
  558. ************************************************************************/
  559. #if defined(CONFIG_PCI)
  560. int is_pci_host(struct pci_controller *hose)
  561. {
  562. /* Bamboo is always configured as host. */
  563. return (1);
  564. }
  565. #endif /* defined(CONFIG_PCI) */
  566. /*----------------------------------------------------------------------------+
  567. | is_powerpc440ep_pass1.
  568. +----------------------------------------------------------------------------*/
  569. int is_powerpc440ep_pass1(void)
  570. {
  571. unsigned long pvr;
  572. pvr = get_pvr();
  573. if (pvr == PVR_POWERPC_440EP_PASS1)
  574. return TRUE;
  575. else if (pvr == PVR_POWERPC_440EP_PASS2)
  576. return FALSE;
  577. else {
  578. printf("brdutil error 3\n");
  579. for (;;)
  580. ;
  581. }
  582. return(FALSE);
  583. }
  584. /*----------------------------------------------------------------------------+
  585. | is_nand_selected.
  586. +----------------------------------------------------------------------------*/
  587. int is_nand_selected(void)
  588. {
  589. #ifdef CONFIG_BAMBOO_NAND
  590. return TRUE;
  591. #else
  592. return FALSE;
  593. #endif
  594. }
  595. /*----------------------------------------------------------------------------+
  596. | config_on_ebc_cs4_is_small_flash => from EPLD
  597. +----------------------------------------------------------------------------*/
  598. unsigned char config_on_ebc_cs4_is_small_flash(void)
  599. {
  600. /* Not implemented yet => returns constant value */
  601. return TRUE;
  602. }
  603. /*----------------------------------------------------------------------------+
  604. | Ext_bus_cntlr_init.
  605. | Initialize the external bus controller
  606. +----------------------------------------------------------------------------*/
  607. void ext_bus_cntlr_init(void)
  608. {
  609. unsigned long sdr0_pstrp0, sdr0_sdstp1;
  610. unsigned long bootstrap_settings, boot_selection, ebc_boot_size;
  611. int computed_boot_device = BOOT_DEVICE_UNKNOWN;
  612. unsigned long ebc0_cs0_bnap_value = 0, ebc0_cs0_bncr_value = 0;
  613. unsigned long ebc0_cs1_bnap_value = 0, ebc0_cs1_bncr_value = 0;
  614. unsigned long ebc0_cs2_bnap_value = 0, ebc0_cs2_bncr_value = 0;
  615. unsigned long ebc0_cs3_bnap_value = 0, ebc0_cs3_bncr_value = 0;
  616. unsigned long ebc0_cs4_bnap_value = 0, ebc0_cs4_bncr_value = 0;
  617. /*-------------------------------------------------------------------------+
  618. |
  619. | PART 1 : Initialize EBC Bank 5
  620. | ==============================
  621. | Bank5 is always associated to the NVRAM/EPLD.
  622. | It has to be initialized prior to other banks settings computation since
  623. | some board registers values may be needed
  624. |
  625. +-------------------------------------------------------------------------*/
  626. /* NVRAM - FPGA */
  627. mtebc(pb5ap, EBC0_BNAP_NVRAM_FPGA);
  628. mtebc(pb5cr, EBC0_BNCR_NVRAM_FPGA_CS5);
  629. /*-------------------------------------------------------------------------+
  630. |
  631. | PART 2 : Determine which boot device was selected
  632. | =========================================
  633. |
  634. | Read Pin Strap Register in PPC440EP
  635. | In case of boot from IIC, read Serial Device Strap Register1
  636. |
  637. | Result can either be :
  638. | - Boot from EBC 8bits => SMALL FLASH
  639. | - Boot from EBC 16bits => Large Flash or SRAM
  640. | - Boot from NAND Flash
  641. | - Boot from PCI
  642. |
  643. +-------------------------------------------------------------------------*/
  644. /* Read Pin Strap Register in PPC440EP */
  645. mfsdr(sdr_pstrp0, sdr0_pstrp0);
  646. bootstrap_settings = sdr0_pstrp0 & SDR0_PSTRP0_BOOTSTRAP_MASK;
  647. /*-------------------------------------------------------------------------+
  648. | PPC440EP Pass1
  649. +-------------------------------------------------------------------------*/
  650. if (is_powerpc440ep_pass1() == TRUE) {
  651. switch(bootstrap_settings) {
  652. case SDR0_PSTRP0_BOOTSTRAP_SETTINGS0:
  653. /* Default Strap Settings 0 : CPU 400 - PLB 133 - Boot EBC 8 bit 33MHz */
  654. /* Boot from Small Flash */
  655. computed_boot_device = BOOT_FROM_SMALL_FLASH;
  656. break;
  657. case SDR0_PSTRP0_BOOTSTRAP_SETTINGS1:
  658. /* Default Strap Settings 1 : CPU 533 - PLB 133 - Boot PCI 66MHz */
  659. /* Boot from PCI */
  660. computed_boot_device = BOOT_FROM_PCI;
  661. break;
  662. case SDR0_PSTRP0_BOOTSTRAP_SETTINGS2:
  663. /* Default Strap Settings 2 : CPU 500 - PLB 100 - Boot NDFC16 66MHz */
  664. /* Boot from Nand Flash */
  665. computed_boot_device = BOOT_FROM_NAND_FLASH0;
  666. break;
  667. case SDR0_PSTRP0_BOOTSTRAP_SETTINGS3:
  668. /* Default Strap Settings 3 : CPU 333 - PLB 133 - Boot EBC 8 bit 66MHz */
  669. /* Boot from Small Flash */
  670. computed_boot_device = BOOT_FROM_SMALL_FLASH;
  671. break;
  672. case SDR0_PSTRP0_BOOTSTRAP_IIC_A8_EN:
  673. case SDR0_PSTRP0_BOOTSTRAP_IIC_A4_EN:
  674. /* Boot Settings in IIC EEprom address 0xA8 or 0xA4 */
  675. /* Read Serial Device Strap Register1 in PPC440EP */
  676. mfsdr(sdr_sdstp1, sdr0_sdstp1);
  677. boot_selection = sdr0_sdstp1 & SDR0_SDSTP1_BOOT_SEL_MASK;
  678. ebc_boot_size = sdr0_sdstp1 & SDR0_SDSTP1_EBC_ROM_BS_MASK;
  679. switch(boot_selection) {
  680. case SDR0_SDSTP1_BOOT_SEL_EBC:
  681. switch(ebc_boot_size) {
  682. case SDR0_SDSTP1_EBC_ROM_BS_16BIT:
  683. computed_boot_device = BOOT_FROM_LARGE_FLASH_OR_SRAM;
  684. break;
  685. case SDR0_SDSTP1_EBC_ROM_BS_8BIT:
  686. computed_boot_device = BOOT_FROM_SMALL_FLASH;
  687. break;
  688. }
  689. break;
  690. case SDR0_SDSTP1_BOOT_SEL_PCI:
  691. computed_boot_device = BOOT_FROM_PCI;
  692. break;
  693. case SDR0_SDSTP1_BOOT_SEL_NDFC:
  694. computed_boot_device = BOOT_FROM_NAND_FLASH0;
  695. break;
  696. }
  697. break;
  698. }
  699. }
  700. /*-------------------------------------------------------------------------+
  701. | PPC440EP Pass2
  702. +-------------------------------------------------------------------------*/
  703. else {
  704. switch(bootstrap_settings) {
  705. case SDR0_PSTRP0_BOOTSTRAP_SETTINGS0:
  706. /* Default Strap Settings 0 : CPU 400 - PLB 133 - Boot EBC 8 bit 33MHz */
  707. /* Boot from Small Flash */
  708. computed_boot_device = BOOT_FROM_SMALL_FLASH;
  709. break;
  710. case SDR0_PSTRP0_BOOTSTRAP_SETTINGS1:
  711. /* Default Strap Settings 1 : CPU 333 - PLB 133 - Boot PCI 66MHz */
  712. /* Boot from PCI */
  713. computed_boot_device = BOOT_FROM_PCI;
  714. break;
  715. case SDR0_PSTRP0_BOOTSTRAP_SETTINGS2:
  716. /* Default Strap Settings 2 : CPU 400 - PLB 100 - Boot NDFC16 33MHz */
  717. /* Boot from Nand Flash */
  718. computed_boot_device = BOOT_FROM_NAND_FLASH0;
  719. break;
  720. case SDR0_PSTRP0_BOOTSTRAP_SETTINGS3:
  721. /* Default Strap Settings 3 : CPU 400 - PLB 100 - Boot EBC 16 bit 33MHz */
  722. /* Boot from Large Flash or SRAM */
  723. computed_boot_device = BOOT_FROM_LARGE_FLASH_OR_SRAM;
  724. break;
  725. case SDR0_PSTRP0_BOOTSTRAP_SETTINGS4:
  726. /* Default Strap Settings 4 : CPU 333 - PLB 133 - Boot EBC 16 bit 66MHz */
  727. /* Boot from Large Flash or SRAM */
  728. computed_boot_device = BOOT_FROM_LARGE_FLASH_OR_SRAM;
  729. break;
  730. case SDR0_PSTRP0_BOOTSTRAP_SETTINGS6:
  731. /* Default Strap Settings 6 : CPU 400 - PLB 100 - Boot PCI 33MHz */
  732. /* Boot from PCI */
  733. computed_boot_device = BOOT_FROM_PCI;
  734. break;
  735. case SDR0_PSTRP0_BOOTSTRAP_IIC_A8_EN:
  736. case SDR0_PSTRP0_BOOTSTRAP_IIC_A4_EN:
  737. /* Default Strap Settings 5-7 */
  738. /* Boot Settings in IIC EEprom address 0xA8 or 0xA4 */
  739. /* Read Serial Device Strap Register1 in PPC440EP */
  740. mfsdr(sdr_sdstp1, sdr0_sdstp1);
  741. boot_selection = sdr0_sdstp1 & SDR0_SDSTP1_BOOT_SEL_MASK;
  742. ebc_boot_size = sdr0_sdstp1 & SDR0_SDSTP1_EBC_ROM_BS_MASK;
  743. switch(boot_selection) {
  744. case SDR0_SDSTP1_BOOT_SEL_EBC:
  745. switch(ebc_boot_size) {
  746. case SDR0_SDSTP1_EBC_ROM_BS_16BIT:
  747. computed_boot_device = BOOT_FROM_LARGE_FLASH_OR_SRAM;
  748. break;
  749. case SDR0_SDSTP1_EBC_ROM_BS_8BIT:
  750. computed_boot_device = BOOT_FROM_SMALL_FLASH;
  751. break;
  752. }
  753. break;
  754. case SDR0_SDSTP1_BOOT_SEL_PCI:
  755. computed_boot_device = BOOT_FROM_PCI;
  756. break;
  757. case SDR0_SDSTP1_BOOT_SEL_NDFC:
  758. computed_boot_device = BOOT_FROM_NAND_FLASH0;
  759. break;
  760. }
  761. break;
  762. }
  763. }
  764. /*-------------------------------------------------------------------------+
  765. |
  766. | PART 3 : Compute EBC settings depending on selected boot device
  767. | ====== ======================================================
  768. |
  769. | Resulting EBC init will be among following configurations :
  770. |
  771. | - Boot from EBC 8bits => boot from SMALL FLASH selected
  772. | EBC-CS0 = Small Flash
  773. | EBC-CS1,2,3 = NAND Flash or
  774. | Exp.Slot depending on Soft Config
  775. | EBC-CS4 = SRAM/Large Flash or
  776. | Large Flash/SRAM depending on jumpers
  777. | EBC-CS5 = NVRAM / EPLD
  778. |
  779. | - Boot from EBC 16bits => boot from Large Flash or SRAM selected
  780. | EBC-CS0 = SRAM/Large Flash or
  781. | Large Flash/SRAM depending on jumpers
  782. | EBC-CS1,2,3 = NAND Flash or
  783. | Exp.Slot depending on Software Configuration
  784. | EBC-CS4 = Small Flash
  785. | EBC-CS5 = NVRAM / EPLD
  786. |
  787. | - Boot from NAND Flash
  788. | EBC-CS0 = NAND Flash0
  789. | EBC-CS1,2,3 = NAND Flash1
  790. | EBC-CS4 = SRAM/Large Flash or
  791. | Large Flash/SRAM depending on jumpers
  792. | EBC-CS5 = NVRAM / EPLD
  793. |
  794. | - Boot from PCI
  795. | EBC-CS0 = ...
  796. | EBC-CS1,2,3 = NAND Flash or
  797. | Exp.Slot depending on Software Configuration
  798. | EBC-CS4 = SRAM/Large Flash or
  799. | Large Flash/SRAM or
  800. | Small Flash depending on jumpers
  801. | EBC-CS5 = NVRAM / EPLD
  802. |
  803. +-------------------------------------------------------------------------*/
  804. switch(computed_boot_device) {
  805. /*------------------------------------------------------------------------- */
  806. case BOOT_FROM_SMALL_FLASH:
  807. /*------------------------------------------------------------------------- */
  808. ebc0_cs0_bnap_value = EBC0_BNAP_SMALL_FLASH;
  809. ebc0_cs0_bncr_value = EBC0_BNCR_SMALL_FLASH_CS0;
  810. if ((is_nand_selected()) == TRUE) {
  811. /* NAND Flash */
  812. ebc0_cs1_bnap_value = EBC0_BNAP_NAND_FLASH;
  813. ebc0_cs1_bncr_value = EBC0_BNCR_NAND_FLASH_CS1;
  814. ebc0_cs2_bnap_value = EBC0_BNAP_NAND_FLASH;
  815. ebc0_cs2_bncr_value = EBC0_BNCR_NAND_FLASH_CS2;
  816. ebc0_cs3_bnap_value = 0;
  817. ebc0_cs3_bncr_value = 0;
  818. } else {
  819. /* Expansion Slot */
  820. ebc0_cs1_bnap_value = 0;
  821. ebc0_cs1_bncr_value = 0;
  822. ebc0_cs2_bnap_value = 0;
  823. ebc0_cs2_bncr_value = 0;
  824. ebc0_cs3_bnap_value = 0;
  825. ebc0_cs3_bncr_value = 0;
  826. }
  827. ebc0_cs4_bnap_value = EBC0_BNAP_LARGE_FLASH_OR_SRAM;
  828. ebc0_cs4_bncr_value = EBC0_BNCR_LARGE_FLASH_OR_SRAM_CS4;
  829. break;
  830. /*------------------------------------------------------------------------- */
  831. case BOOT_FROM_LARGE_FLASH_OR_SRAM:
  832. /*------------------------------------------------------------------------- */
  833. ebc0_cs0_bnap_value = EBC0_BNAP_LARGE_FLASH_OR_SRAM;
  834. ebc0_cs0_bncr_value = EBC0_BNCR_LARGE_FLASH_OR_SRAM_CS0;
  835. if ((is_nand_selected()) == TRUE) {
  836. /* NAND Flash */
  837. ebc0_cs1_bnap_value = EBC0_BNAP_NAND_FLASH;
  838. ebc0_cs1_bncr_value = EBC0_BNCR_NAND_FLASH_CS1;
  839. ebc0_cs2_bnap_value = 0;
  840. ebc0_cs2_bncr_value = 0;
  841. ebc0_cs3_bnap_value = 0;
  842. ebc0_cs3_bncr_value = 0;
  843. } else {
  844. /* Expansion Slot */
  845. ebc0_cs1_bnap_value = 0;
  846. ebc0_cs1_bncr_value = 0;
  847. ebc0_cs2_bnap_value = 0;
  848. ebc0_cs2_bncr_value = 0;
  849. ebc0_cs3_bnap_value = 0;
  850. ebc0_cs3_bncr_value = 0;
  851. }
  852. ebc0_cs4_bnap_value = EBC0_BNAP_SMALL_FLASH;
  853. ebc0_cs4_bncr_value = EBC0_BNCR_SMALL_FLASH_CS4;
  854. break;
  855. /*------------------------------------------------------------------------- */
  856. case BOOT_FROM_NAND_FLASH0:
  857. /*------------------------------------------------------------------------- */
  858. ebc0_cs0_bnap_value = 0;
  859. ebc0_cs0_bncr_value = 0;
  860. ebc0_cs1_bnap_value = EBC0_BNAP_NAND_FLASH;
  861. ebc0_cs1_bncr_value = EBC0_BNCR_NAND_FLASH_CS1;
  862. ebc0_cs2_bnap_value = 0;
  863. ebc0_cs2_bncr_value = 0;
  864. ebc0_cs3_bnap_value = 0;
  865. ebc0_cs3_bncr_value = 0;
  866. /* Large Flash or SRAM */
  867. ebc0_cs4_bnap_value = EBC0_BNAP_LARGE_FLASH_OR_SRAM;
  868. ebc0_cs4_bncr_value = EBC0_BNCR_LARGE_FLASH_OR_SRAM_CS4;
  869. break;
  870. /*------------------------------------------------------------------------- */
  871. case BOOT_FROM_PCI:
  872. /*------------------------------------------------------------------------- */
  873. ebc0_cs0_bnap_value = 0;
  874. ebc0_cs0_bncr_value = 0;
  875. if ((is_nand_selected()) == TRUE) {
  876. /* NAND Flash */
  877. ebc0_cs1_bnap_value = EBC0_BNAP_NAND_FLASH;
  878. ebc0_cs1_bncr_value = EBC0_BNCR_NAND_FLASH_CS1;
  879. ebc0_cs2_bnap_value = 0;
  880. ebc0_cs2_bncr_value = 0;
  881. ebc0_cs3_bnap_value = 0;
  882. ebc0_cs3_bncr_value = 0;
  883. } else {
  884. /* Expansion Slot */
  885. ebc0_cs1_bnap_value = 0;
  886. ebc0_cs1_bncr_value = 0;
  887. ebc0_cs2_bnap_value = 0;
  888. ebc0_cs2_bncr_value = 0;
  889. ebc0_cs3_bnap_value = 0;
  890. ebc0_cs3_bncr_value = 0;
  891. }
  892. if ((config_on_ebc_cs4_is_small_flash()) == TRUE) {
  893. /* Small Flash */
  894. ebc0_cs4_bnap_value = EBC0_BNAP_SMALL_FLASH;
  895. ebc0_cs4_bncr_value = EBC0_BNCR_SMALL_FLASH_CS4;
  896. } else {
  897. /* Large Flash or SRAM */
  898. ebc0_cs4_bnap_value = EBC0_BNAP_LARGE_FLASH_OR_SRAM;
  899. ebc0_cs4_bncr_value = EBC0_BNCR_LARGE_FLASH_OR_SRAM_CS4;
  900. }
  901. break;
  902. /*------------------------------------------------------------------------- */
  903. case BOOT_DEVICE_UNKNOWN:
  904. /*------------------------------------------------------------------------- */
  905. /* Error */
  906. break;
  907. }
  908. /*-------------------------------------------------------------------------+
  909. | Initialize EBC CONFIG
  910. +-------------------------------------------------------------------------*/
  911. mtdcr(ebccfga, xbcfg);
  912. mtdcr(ebccfgd, EBC0_CFG_EBTC_DRIVEN |
  913. EBC0_CFG_PTD_ENABLED |
  914. EBC0_CFG_RTC_2048PERCLK |
  915. EBC0_CFG_EMPL_LOW |
  916. EBC0_CFG_EMPH_LOW |
  917. EBC0_CFG_CSTC_DRIVEN |
  918. EBC0_CFG_BPF_ONEDW |
  919. EBC0_CFG_EMS_8BIT |
  920. EBC0_CFG_PME_DISABLED |
  921. EBC0_CFG_PMT_ENCODE(0) );
  922. /*-------------------------------------------------------------------------+
  923. | Initialize EBC Bank 0-4
  924. +-------------------------------------------------------------------------*/
  925. /* EBC Bank0 */
  926. mtebc(pb0ap, ebc0_cs0_bnap_value);
  927. mtebc(pb0cr, ebc0_cs0_bncr_value);
  928. /* EBC Bank1 */
  929. mtebc(pb1ap, ebc0_cs1_bnap_value);
  930. mtebc(pb1cr, ebc0_cs1_bncr_value);
  931. /* EBC Bank2 */
  932. mtebc(pb2ap, ebc0_cs2_bnap_value);
  933. mtebc(pb2cr, ebc0_cs2_bncr_value);
  934. /* EBC Bank3 */
  935. mtebc(pb3ap, ebc0_cs3_bnap_value);
  936. mtebc(pb3cr, ebc0_cs3_bncr_value);
  937. /* EBC Bank4 */
  938. mtebc(pb4ap, ebc0_cs4_bnap_value);
  939. mtebc(pb4cr, ebc0_cs4_bncr_value);
  940. return;
  941. }
  942. /*----------------------------------------------------------------------------+
  943. | get_uart_configuration.
  944. +----------------------------------------------------------------------------*/
  945. uart_config_nb_t get_uart_configuration(void)
  946. {
  947. return (L4);
  948. }
  949. /*----------------------------------------------------------------------------+
  950. | set_phy_configuration_through_fpga => to EPLD
  951. +----------------------------------------------------------------------------*/
  952. void set_phy_configuration_through_fpga(zmii_config_t config)
  953. {
  954. unsigned long fpga_selection_reg;
  955. fpga_selection_reg = in8(FPGA_SELECTION_1_REG) & ~FPGA_SEL_1_REG_PHY_MASK;
  956. switch(config)
  957. {
  958. case ZMII_CONFIGURATION_IS_MII:
  959. fpga_selection_reg = fpga_selection_reg | FPGA_SEL_1_REG_MII;
  960. break;
  961. case ZMII_CONFIGURATION_IS_RMII:
  962. fpga_selection_reg = fpga_selection_reg | FPGA_SEL_1_REG_RMII;
  963. break;
  964. case ZMII_CONFIGURATION_IS_SMII:
  965. fpga_selection_reg = fpga_selection_reg | FPGA_SEL_1_REG_SMII;
  966. break;
  967. case ZMII_CONFIGURATION_UNKNOWN:
  968. default:
  969. break;
  970. }
  971. out8(FPGA_SELECTION_1_REG,fpga_selection_reg);
  972. }
  973. /*----------------------------------------------------------------------------+
  974. | scp_selection_in_fpga.
  975. +----------------------------------------------------------------------------*/
  976. void scp_selection_in_fpga(void)
  977. {
  978. unsigned long fpga_selection_2_reg;
  979. fpga_selection_2_reg = in8(FPGA_SELECTION_2_REG) & ~FPGA_SEL2_REG_IIC1_SCP_SEL_MASK;
  980. fpga_selection_2_reg |= FPGA_SEL2_REG_SEL_SCP;
  981. out8(FPGA_SELECTION_2_REG,fpga_selection_2_reg);
  982. }
  983. /*----------------------------------------------------------------------------+
  984. | iic1_selection_in_fpga.
  985. +----------------------------------------------------------------------------*/
  986. void iic1_selection_in_fpga(void)
  987. {
  988. unsigned long fpga_selection_2_reg;
  989. fpga_selection_2_reg = in8(FPGA_SELECTION_2_REG) & ~FPGA_SEL2_REG_IIC1_SCP_SEL_MASK;
  990. fpga_selection_2_reg |= FPGA_SEL2_REG_SEL_IIC1;
  991. out8(FPGA_SELECTION_2_REG,fpga_selection_2_reg);
  992. }
  993. /*----------------------------------------------------------------------------+
  994. | dma_a_b_selection_in_fpga.
  995. +----------------------------------------------------------------------------*/
  996. void dma_a_b_selection_in_fpga(void)
  997. {
  998. unsigned long fpga_selection_2_reg;
  999. fpga_selection_2_reg = in8(FPGA_SELECTION_2_REG) | FPGA_SEL2_REG_SEL_DMA_A_B;
  1000. out8(FPGA_SELECTION_2_REG,fpga_selection_2_reg);
  1001. }
  1002. /*----------------------------------------------------------------------------+
  1003. | dma_a_b_unselect_in_fpga.
  1004. +----------------------------------------------------------------------------*/
  1005. void dma_a_b_unselect_in_fpga(void)
  1006. {
  1007. unsigned long fpga_selection_2_reg;
  1008. fpga_selection_2_reg = in8(FPGA_SELECTION_2_REG) & ~FPGA_SEL2_REG_SEL_DMA_A_B;
  1009. out8(FPGA_SELECTION_2_REG,fpga_selection_2_reg);
  1010. }
  1011. /*----------------------------------------------------------------------------+
  1012. | dma_c_d_selection_in_fpga.
  1013. +----------------------------------------------------------------------------*/
  1014. void dma_c_d_selection_in_fpga(void)
  1015. {
  1016. unsigned long fpga_selection_2_reg;
  1017. fpga_selection_2_reg = in8(FPGA_SELECTION_2_REG) | FPGA_SEL2_REG_SEL_DMA_C_D;
  1018. out8(FPGA_SELECTION_2_REG,fpga_selection_2_reg);
  1019. }
  1020. /*----------------------------------------------------------------------------+
  1021. | dma_c_d_unselect_in_fpga.
  1022. +----------------------------------------------------------------------------*/
  1023. void dma_c_d_unselect_in_fpga(void)
  1024. {
  1025. unsigned long fpga_selection_2_reg;
  1026. fpga_selection_2_reg = in8(FPGA_SELECTION_2_REG) & ~FPGA_SEL2_REG_SEL_DMA_C_D;
  1027. out8(FPGA_SELECTION_2_REG,fpga_selection_2_reg);
  1028. }
  1029. /*----------------------------------------------------------------------------+
  1030. | usb2_device_selection_in_fpga.
  1031. +----------------------------------------------------------------------------*/
  1032. void usb2_device_selection_in_fpga(void)
  1033. {
  1034. unsigned long fpga_selection_1_reg;
  1035. fpga_selection_1_reg = in8(FPGA_SELECTION_1_REG) | FPGA_SEL_1_REG_USB2_DEV_SEL;
  1036. out8(FPGA_SELECTION_1_REG,fpga_selection_1_reg);
  1037. }
  1038. /*----------------------------------------------------------------------------+
  1039. | usb2_device_reset_through_fpga.
  1040. +----------------------------------------------------------------------------*/
  1041. void usb2_device_reset_through_fpga(void)
  1042. {
  1043. /* Perform soft Reset pulse */
  1044. unsigned long fpga_reset_reg;
  1045. int i;
  1046. fpga_reset_reg = in8(FPGA_RESET_REG);
  1047. out8(FPGA_RESET_REG,fpga_reset_reg | FPGA_RESET_REG_RESET_USB20_DEV);
  1048. for (i=0; i<500; i++)
  1049. udelay(1000);
  1050. out8(FPGA_RESET_REG,fpga_reset_reg);
  1051. }
  1052. /*----------------------------------------------------------------------------+
  1053. | usb2_host_selection_in_fpga.
  1054. +----------------------------------------------------------------------------*/
  1055. void usb2_host_selection_in_fpga(void)
  1056. {
  1057. unsigned long fpga_selection_1_reg;
  1058. fpga_selection_1_reg = in8(FPGA_SELECTION_1_REG) | FPGA_SEL_1_REG_USB2_HOST_SEL;
  1059. out8(FPGA_SELECTION_1_REG,fpga_selection_1_reg);
  1060. }
  1061. /*----------------------------------------------------------------------------+
  1062. | ndfc_selection_in_fpga.
  1063. +----------------------------------------------------------------------------*/
  1064. void ndfc_selection_in_fpga(void)
  1065. {
  1066. unsigned long fpga_selection_1_reg;
  1067. fpga_selection_1_reg = in8(FPGA_SELECTION_1_REG) &~FPGA_SEL_1_REG_NF_SELEC_MASK;
  1068. fpga_selection_1_reg |= FPGA_SEL_1_REG_NF0_SEL_BY_NFCS1;
  1069. fpga_selection_1_reg |= FPGA_SEL_1_REG_NF1_SEL_BY_NFCS2;
  1070. out8(FPGA_SELECTION_1_REG,fpga_selection_1_reg);
  1071. }
  1072. /*----------------------------------------------------------------------------+
  1073. | uart_selection_in_fpga.
  1074. +----------------------------------------------------------------------------*/
  1075. void uart_selection_in_fpga(uart_config_nb_t uart_config)
  1076. {
  1077. /* FPGA register */
  1078. unsigned char fpga_selection_3_reg;
  1079. /* Read FPGA Reagister */
  1080. fpga_selection_3_reg = in8(FPGA_SELECTION_3_REG);
  1081. switch (uart_config)
  1082. {
  1083. case L1:
  1084. /* ----------------------------------------------------------------------- */
  1085. /* L1 configuration: UART0 = 8 pins */
  1086. /* ----------------------------------------------------------------------- */
  1087. /* Configure FPGA */
  1088. fpga_selection_3_reg = fpga_selection_3_reg & ~FPGA_SEL3_REG_SEL_UART_CONFIG_MASK;
  1089. fpga_selection_3_reg = fpga_selection_3_reg | FPGA_SEL3_REG_SEL_UART_CONFIG1;
  1090. out8(FPGA_SELECTION_3_REG, fpga_selection_3_reg);
  1091. break;
  1092. case L2:
  1093. /* ----------------------------------------------------------------------- */
  1094. /* L2 configuration: UART0 = 4 pins */
  1095. /* UART1 = 4 pins */
  1096. /* ----------------------------------------------------------------------- */
  1097. /* Configure FPGA */
  1098. fpga_selection_3_reg = fpga_selection_3_reg & ~FPGA_SEL3_REG_SEL_UART_CONFIG_MASK;
  1099. fpga_selection_3_reg = fpga_selection_3_reg | FPGA_SEL3_REG_SEL_UART_CONFIG2;
  1100. out8(FPGA_SELECTION_3_REG, fpga_selection_3_reg);
  1101. break;
  1102. case L3:
  1103. /* ----------------------------------------------------------------------- */
  1104. /* L3 configuration: UART0 = 4 pins */
  1105. /* UART1 = 2 pins */
  1106. /* UART2 = 2 pins */
  1107. /* ----------------------------------------------------------------------- */
  1108. /* Configure FPGA */
  1109. fpga_selection_3_reg = fpga_selection_3_reg & ~FPGA_SEL3_REG_SEL_UART_CONFIG_MASK;
  1110. fpga_selection_3_reg = fpga_selection_3_reg | FPGA_SEL3_REG_SEL_UART_CONFIG3;
  1111. out8(FPGA_SELECTION_3_REG, fpga_selection_3_reg);
  1112. break;
  1113. case L4:
  1114. /* Configure FPGA */
  1115. fpga_selection_3_reg = fpga_selection_3_reg & ~FPGA_SEL3_REG_SEL_UART_CONFIG_MASK;
  1116. fpga_selection_3_reg = fpga_selection_3_reg | FPGA_SEL3_REG_SEL_UART_CONFIG4;
  1117. out8(FPGA_SELECTION_3_REG, fpga_selection_3_reg);
  1118. break;
  1119. default:
  1120. /* Unsupported UART configuration number */
  1121. for (;;)
  1122. ;
  1123. break;
  1124. }
  1125. }
  1126. /*----------------------------------------------------------------------------+
  1127. | init_default_gpio
  1128. +----------------------------------------------------------------------------*/
  1129. void init_default_gpio(void)
  1130. {
  1131. int i;
  1132. /* Init GPIO0 */
  1133. for(i=0; i<GPIO_MAX; i++)
  1134. {
  1135. gpio_tab[GPIO0][i].add = GPIO0_BASE;
  1136. gpio_tab[GPIO0][i].in_out = GPIO_DIS;
  1137. gpio_tab[GPIO0][i].alt_nb = GPIO_SEL;
  1138. }
  1139. /* Init GPIO1 */
  1140. for(i=0; i<GPIO_MAX; i++)
  1141. {
  1142. gpio_tab[GPIO1][i].add = GPIO1_BASE;
  1143. gpio_tab[GPIO1][i].in_out = GPIO_DIS;
  1144. gpio_tab[GPIO1][i].alt_nb = GPIO_SEL;
  1145. }
  1146. /* EBC_CS_N(5) - GPIO0_10 */
  1147. gpio_tab[GPIO0][10].in_out = GPIO_OUT;
  1148. gpio_tab[GPIO0][10].alt_nb = GPIO_ALT1;
  1149. /* EBC_CS_N(4) - GPIO0_9 */
  1150. gpio_tab[GPIO0][9].in_out = GPIO_OUT;
  1151. gpio_tab[GPIO0][9].alt_nb = GPIO_ALT1;
  1152. }
  1153. /*----------------------------------------------------------------------------+
  1154. | update_uart_ios
  1155. +------------------------------------------------------------------------------
  1156. |
  1157. | Set UART Configuration in PowerPC440EP
  1158. |
  1159. | +---------------------------------------------------------------------+
  1160. | | Configuartion | Connector | Nb of pins | Pins | Associated |
  1161. | | Number | Port Name | available | naming | CORE |
  1162. | +-----------------+---------------+------------+--------+-------------+
  1163. | | L1 | Port_A | 8 | UART | UART core 0 |
  1164. | +-----------------+---------------+------------+--------+-------------+
  1165. | | L2 | Port_A | 4 | UART1 | UART core 0 |
  1166. | | (L2D) | Port_B | 4 | UART2 | UART core 1 |
  1167. | +-----------------+---------------+------------+--------+-------------+
  1168. | | L3 | Port_A | 4 | UART1 | UART core 0 |
  1169. | | (L3D) | Port_B | 2 | UART2 | UART core 1 |
  1170. | | | Port_C | 2 | UART3 | UART core 2 |
  1171. | +-----------------+---------------+------------+--------+-------------+
  1172. | | | Port_A | 2 | UART1 | UART core 0 |
  1173. | | L4 | Port_B | 2 | UART2 | UART core 1 |
  1174. | | (L4D) | Port_C | 2 | UART3 | UART core 2 |
  1175. | | | Port_D | 2 | UART4 | UART core 3 |
  1176. | +-----------------+---------------+------------+--------+-------------+
  1177. |
  1178. | Involved GPIOs
  1179. |
  1180. | +------------------------------------------------------------------------------+
  1181. | | GPIO | Aternate 1 | I/O | Alternate 2 | I/O | Alternate 3 | I/O |
  1182. | +---------+------------------+-----+-----------------+-----+-------------+-----+
  1183. | | GPIO1_2 | UART0_DCD_N | I | UART1_DSR_CTS_N | I | UART2_SOUT | O |
  1184. | | GPIO1_3 | UART0_8PIN_DSR_N | I | UART1_RTS_DTR_N | O | UART2_SIN | I |
  1185. | | GPIO1_4 | UART0_8PIN_CTS_N | I | NA | NA | UART3_SIN | I |
  1186. | | GPIO1_5 | UART0_RTS_N | O | NA | NA | UART3_SOUT | O |
  1187. | | GPIO1_6 | UART0_DTR_N | O | UART1_SOUT | O | NA | NA |
  1188. | | GPIO1_7 | UART0_RI_N | I | UART1_SIN | I | NA | NA |
  1189. | +------------------------------------------------------------------------------+
  1190. |
  1191. |
  1192. +----------------------------------------------------------------------------*/
  1193. void update_uart_ios(uart_config_nb_t uart_config)
  1194. {
  1195. switch (uart_config)
  1196. {
  1197. case L1:
  1198. /* ----------------------------------------------------------------------- */
  1199. /* L1 configuration: UART0 = 8 pins */
  1200. /* ----------------------------------------------------------------------- */
  1201. /* Update GPIO Configuration Table */
  1202. gpio_tab[GPIO1][2].in_out = GPIO_IN;
  1203. gpio_tab[GPIO1][2].alt_nb = GPIO_ALT1;
  1204. gpio_tab[GPIO1][3].in_out = GPIO_IN;
  1205. gpio_tab[GPIO1][3].alt_nb = GPIO_ALT1;
  1206. gpio_tab[GPIO1][4].in_out = GPIO_IN;
  1207. gpio_tab[GPIO1][4].alt_nb = GPIO_ALT1;
  1208. gpio_tab[GPIO1][5].in_out = GPIO_OUT;
  1209. gpio_tab[GPIO1][5].alt_nb = GPIO_ALT1;
  1210. gpio_tab[GPIO1][6].in_out = GPIO_OUT;
  1211. gpio_tab[GPIO1][6].alt_nb = GPIO_ALT1;
  1212. gpio_tab[GPIO1][7].in_out = GPIO_IN;
  1213. gpio_tab[GPIO1][7].alt_nb = GPIO_ALT1;
  1214. break;
  1215. case L2:
  1216. /* ----------------------------------------------------------------------- */
  1217. /* L2 configuration: UART0 = 4 pins */
  1218. /* UART1 = 4 pins */
  1219. /* ----------------------------------------------------------------------- */
  1220. /* Update GPIO Configuration Table */
  1221. gpio_tab[GPIO1][2].in_out = GPIO_IN;
  1222. gpio_tab[GPIO1][2].alt_nb = GPIO_ALT2;
  1223. gpio_tab[GPIO1][3].in_out = GPIO_OUT;
  1224. gpio_tab[GPIO1][3].alt_nb = GPIO_ALT2;
  1225. gpio_tab[GPIO1][4].in_out = GPIO_IN;
  1226. gpio_tab[GPIO1][4].alt_nb = GPIO_ALT1;
  1227. gpio_tab[GPIO1][5].in_out = GPIO_OUT;
  1228. gpio_tab[GPIO1][5].alt_nb = GPIO_ALT1;
  1229. gpio_tab[GPIO1][6].in_out = GPIO_OUT;
  1230. gpio_tab[GPIO1][6].alt_nb = GPIO_ALT2;
  1231. gpio_tab[GPIO1][7].in_out = GPIO_IN;
  1232. gpio_tab[GPIO1][7].alt_nb = GPIO_ALT2;
  1233. break;
  1234. case L3:
  1235. /* ----------------------------------------------------------------------- */
  1236. /* L3 configuration: UART0 = 4 pins */
  1237. /* UART1 = 2 pins */
  1238. /* UART2 = 2 pins */
  1239. /* ----------------------------------------------------------------------- */
  1240. /* Update GPIO Configuration Table */
  1241. gpio_tab[GPIO1][2].in_out = GPIO_OUT;
  1242. gpio_tab[GPIO1][2].alt_nb = GPIO_ALT3;
  1243. gpio_tab[GPIO1][3].in_out = GPIO_IN;
  1244. gpio_tab[GPIO1][3].alt_nb = GPIO_ALT3;
  1245. gpio_tab[GPIO1][4].in_out = GPIO_IN;
  1246. gpio_tab[GPIO1][4].alt_nb = GPIO_ALT1;
  1247. gpio_tab[GPIO1][5].in_out = GPIO_OUT;
  1248. gpio_tab[GPIO1][5].alt_nb = GPIO_ALT1;
  1249. gpio_tab[GPIO1][6].in_out = GPIO_OUT;
  1250. gpio_tab[GPIO1][6].alt_nb = GPIO_ALT2;
  1251. gpio_tab[GPIO1][7].in_out = GPIO_IN;
  1252. gpio_tab[GPIO1][7].alt_nb = GPIO_ALT2;
  1253. break;
  1254. case L4:
  1255. /* ----------------------------------------------------------------------- */
  1256. /* L4 configuration: UART0 = 2 pins */
  1257. /* UART1 = 2 pins */
  1258. /* UART2 = 2 pins */
  1259. /* UART3 = 2 pins */
  1260. /* ----------------------------------------------------------------------- */
  1261. /* Update GPIO Configuration Table */
  1262. gpio_tab[GPIO1][2].in_out = GPIO_OUT;
  1263. gpio_tab[GPIO1][2].alt_nb = GPIO_ALT3;
  1264. gpio_tab[GPIO1][3].in_out = GPIO_IN;
  1265. gpio_tab[GPIO1][3].alt_nb = GPIO_ALT3;
  1266. gpio_tab[GPIO1][4].in_out = GPIO_IN;
  1267. gpio_tab[GPIO1][4].alt_nb = GPIO_ALT3;
  1268. gpio_tab[GPIO1][5].in_out = GPIO_OUT;
  1269. gpio_tab[GPIO1][5].alt_nb = GPIO_ALT3;
  1270. gpio_tab[GPIO1][6].in_out = GPIO_OUT;
  1271. gpio_tab[GPIO1][6].alt_nb = GPIO_ALT2;
  1272. gpio_tab[GPIO1][7].in_out = GPIO_IN;
  1273. gpio_tab[GPIO1][7].alt_nb = GPIO_ALT2;
  1274. break;
  1275. default:
  1276. /* Unsupported UART configuration number */
  1277. printf("ERROR - Unsupported UART configuration number.\n\n");
  1278. for (;;)
  1279. ;
  1280. break;
  1281. }
  1282. /* Set input Selection Register on Alt_Receive for UART Input Core */
  1283. out32(GPIO1_IS1L, (in32(GPIO1_IS1L) | 0x0FC30000));
  1284. out32(GPIO1_IS2L, (in32(GPIO1_IS2L) | 0x0C030000));
  1285. out32(GPIO1_IS3L, (in32(GPIO1_IS3L) | 0x03C00000));
  1286. }
  1287. /*----------------------------------------------------------------------------+
  1288. | update_ndfc_ios(void).
  1289. +----------------------------------------------------------------------------*/
  1290. void update_ndfc_ios(void)
  1291. {
  1292. /* Update GPIO Configuration Table */
  1293. gpio_tab[GPIO0][6].in_out = GPIO_OUT; /* EBC_CS_N(1) */
  1294. gpio_tab[GPIO0][6].alt_nb = GPIO_ALT1;
  1295. #if 0
  1296. gpio_tab[GPIO0][7].in_out = GPIO_OUT; /* EBC_CS_N(2) */
  1297. gpio_tab[GPIO0][7].alt_nb = GPIO_ALT1;
  1298. gpio_tab[GPIO0][7].in_out = GPIO_OUT; /* EBC_CS_N(3) */
  1299. gpio_tab[GPIO0][7].alt_nb = GPIO_ALT1;
  1300. #endif
  1301. }
  1302. /*----------------------------------------------------------------------------+
  1303. | update_zii_ios(void).
  1304. +----------------------------------------------------------------------------*/
  1305. void update_zii_ios(void)
  1306. {
  1307. /* Update GPIO Configuration Table */
  1308. gpio_tab[GPIO0][12].in_out = GPIO_IN; /* ZII_p0Rxd(0) */
  1309. gpio_tab[GPIO0][12].alt_nb = GPIO_ALT1;
  1310. gpio_tab[GPIO0][13].in_out = GPIO_IN; /* ZII_p0Rxd(1) */
  1311. gpio_tab[GPIO0][13].alt_nb = GPIO_ALT1;
  1312. gpio_tab[GPIO0][14].in_out = GPIO_IN; /* ZII_p0Rxd(2) */
  1313. gpio_tab[GPIO0][14].alt_nb = GPIO_ALT1;
  1314. gpio_tab[GPIO0][15].in_out = GPIO_IN; /* ZII_p0Rxd(3) */
  1315. gpio_tab[GPIO0][15].alt_nb = GPIO_ALT1;
  1316. gpio_tab[GPIO0][16].in_out = GPIO_OUT; /* ZII_p0Txd(0) */
  1317. gpio_tab[GPIO0][16].alt_nb = GPIO_ALT1;
  1318. gpio_tab[GPIO0][17].in_out = GPIO_OUT; /* ZII_p0Txd(1) */
  1319. gpio_tab[GPIO0][17].alt_nb = GPIO_ALT1;
  1320. gpio_tab[GPIO0][18].in_out = GPIO_OUT; /* ZII_p0Txd(2) */
  1321. gpio_tab[GPIO0][18].alt_nb = GPIO_ALT1;
  1322. gpio_tab[GPIO0][19].in_out = GPIO_OUT; /* ZII_p0Txd(3) */
  1323. gpio_tab[GPIO0][19].alt_nb = GPIO_ALT1;
  1324. gpio_tab[GPIO0][20].in_out = GPIO_IN; /* ZII_p0Rx_er */
  1325. gpio_tab[GPIO0][20].alt_nb = GPIO_ALT1;
  1326. gpio_tab[GPIO0][21].in_out = GPIO_IN; /* ZII_p0Rx_dv */
  1327. gpio_tab[GPIO0][21].alt_nb = GPIO_ALT1;
  1328. gpio_tab[GPIO0][22].in_out = GPIO_IN; /* ZII_p0Crs */
  1329. gpio_tab[GPIO0][22].alt_nb = GPIO_ALT1;
  1330. gpio_tab[GPIO0][23].in_out = GPIO_OUT; /* ZII_p0Tx_er */
  1331. gpio_tab[GPIO0][23].alt_nb = GPIO_ALT1;
  1332. gpio_tab[GPIO0][24].in_out = GPIO_OUT; /* ZII_p0Tx_en */
  1333. gpio_tab[GPIO0][24].alt_nb = GPIO_ALT1;
  1334. gpio_tab[GPIO0][25].in_out = GPIO_IN; /* ZII_p0Col */
  1335. gpio_tab[GPIO0][25].alt_nb = GPIO_ALT1;
  1336. }
  1337. /*----------------------------------------------------------------------------+
  1338. | update_uic_0_3_irq_ios().
  1339. +----------------------------------------------------------------------------*/
  1340. void update_uic_0_3_irq_ios(void)
  1341. {
  1342. gpio_tab[GPIO1][8].in_out = GPIO_IN; /* UIC_IRQ(0) */
  1343. gpio_tab[GPIO1][8].alt_nb = GPIO_ALT1;
  1344. gpio_tab[GPIO1][9].in_out = GPIO_IN; /* UIC_IRQ(1) */
  1345. gpio_tab[GPIO1][9].alt_nb = GPIO_ALT1;
  1346. gpio_tab[GPIO1][10].in_out = GPIO_IN; /* UIC_IRQ(2) */
  1347. gpio_tab[GPIO1][10].alt_nb = GPIO_ALT1;
  1348. gpio_tab[GPIO1][11].in_out = GPIO_IN; /* UIC_IRQ(3) */
  1349. gpio_tab[GPIO1][11].alt_nb = GPIO_ALT1;
  1350. }
  1351. /*----------------------------------------------------------------------------+
  1352. | update_uic_4_9_irq_ios().
  1353. +----------------------------------------------------------------------------*/
  1354. void update_uic_4_9_irq_ios(void)
  1355. {
  1356. gpio_tab[GPIO1][12].in_out = GPIO_IN; /* UIC_IRQ(4) */
  1357. gpio_tab[GPIO1][12].alt_nb = GPIO_ALT1;
  1358. gpio_tab[GPIO1][13].in_out = GPIO_IN; /* UIC_IRQ(6) */
  1359. gpio_tab[GPIO1][13].alt_nb = GPIO_ALT1;
  1360. gpio_tab[GPIO1][14].in_out = GPIO_IN; /* UIC_IRQ(7) */
  1361. gpio_tab[GPIO1][14].alt_nb = GPIO_ALT1;
  1362. gpio_tab[GPIO1][15].in_out = GPIO_IN; /* UIC_IRQ(8) */
  1363. gpio_tab[GPIO1][15].alt_nb = GPIO_ALT1;
  1364. gpio_tab[GPIO1][16].in_out = GPIO_IN; /* UIC_IRQ(9) */
  1365. gpio_tab[GPIO1][16].alt_nb = GPIO_ALT1;
  1366. }
  1367. /*----------------------------------------------------------------------------+
  1368. | update_dma_a_b_ios().
  1369. +----------------------------------------------------------------------------*/
  1370. void update_dma_a_b_ios(void)
  1371. {
  1372. gpio_tab[GPIO1][12].in_out = GPIO_OUT; /* DMA_ACK(1) */
  1373. gpio_tab[GPIO1][12].alt_nb = GPIO_ALT2;
  1374. gpio_tab[GPIO1][13].in_out = GPIO_BI; /* DMA_EOT/TC(1) */
  1375. gpio_tab[GPIO1][13].alt_nb = GPIO_ALT2;
  1376. gpio_tab[GPIO1][14].in_out = GPIO_IN; /* DMA_REQ(0) */
  1377. gpio_tab[GPIO1][14].alt_nb = GPIO_ALT2;
  1378. gpio_tab[GPIO1][15].in_out = GPIO_OUT; /* DMA_ACK(0) */
  1379. gpio_tab[GPIO1][15].alt_nb = GPIO_ALT2;
  1380. gpio_tab[GPIO1][16].in_out = GPIO_BI; /* DMA_EOT/TC(0) */
  1381. gpio_tab[GPIO1][16].alt_nb = GPIO_ALT2;
  1382. }
  1383. /*----------------------------------------------------------------------------+
  1384. | update_dma_c_d_ios().
  1385. +----------------------------------------------------------------------------*/
  1386. void update_dma_c_d_ios(void)
  1387. {
  1388. gpio_tab[GPIO0][0].in_out = GPIO_IN; /* DMA_REQ(2) */
  1389. gpio_tab[GPIO0][0].alt_nb = GPIO_ALT2;
  1390. gpio_tab[GPIO0][1].in_out = GPIO_OUT; /* DMA_ACK(2) */
  1391. gpio_tab[GPIO0][1].alt_nb = GPIO_ALT2;
  1392. gpio_tab[GPIO0][2].in_out = GPIO_BI; /* DMA_EOT/TC(2) */
  1393. gpio_tab[GPIO0][2].alt_nb = GPIO_ALT2;
  1394. gpio_tab[GPIO0][3].in_out = GPIO_IN; /* DMA_REQ(3) */
  1395. gpio_tab[GPIO0][3].alt_nb = GPIO_ALT2;
  1396. gpio_tab[GPIO0][4].in_out = GPIO_OUT; /* DMA_ACK(3) */
  1397. gpio_tab[GPIO0][4].alt_nb = GPIO_ALT2;
  1398. gpio_tab[GPIO0][5].in_out = GPIO_BI; /* DMA_EOT/TC(3) */
  1399. gpio_tab[GPIO0][5].alt_nb = GPIO_ALT2;
  1400. }
  1401. /*----------------------------------------------------------------------------+
  1402. | update_ebc_master_ios().
  1403. +----------------------------------------------------------------------------*/
  1404. void update_ebc_master_ios(void)
  1405. {
  1406. gpio_tab[GPIO0][27].in_out = GPIO_IN; /* EXT_EBC_REQ */
  1407. gpio_tab[GPIO0][27].alt_nb = GPIO_ALT1;
  1408. gpio_tab[GPIO0][29].in_out = GPIO_OUT; /* EBC_EXT_HDLA */
  1409. gpio_tab[GPIO0][29].alt_nb = GPIO_ALT1;
  1410. gpio_tab[GPIO0][30].in_out = GPIO_OUT; /* EBC_EXT_ACK */
  1411. gpio_tab[GPIO0][30].alt_nb = GPIO_ALT1;
  1412. gpio_tab[GPIO0][31].in_out = GPIO_OUT; /* EBC_EXR_BUSREQ */
  1413. gpio_tab[GPIO0][31].alt_nb = GPIO_ALT1;
  1414. }
  1415. /*----------------------------------------------------------------------------+
  1416. | update_usb2_device_ios().
  1417. +----------------------------------------------------------------------------*/
  1418. void update_usb2_device_ios(void)
  1419. {
  1420. gpio_tab[GPIO0][26].in_out = GPIO_IN; /* USB2D_RXVALID */
  1421. gpio_tab[GPIO0][26].alt_nb = GPIO_ALT2;
  1422. gpio_tab[GPIO0][27].in_out = GPIO_IN; /* USB2D_RXERROR */
  1423. gpio_tab[GPIO0][27].alt_nb = GPIO_ALT2;
  1424. gpio_tab[GPIO0][28].in_out = GPIO_OUT; /* USB2D_TXVALID */
  1425. gpio_tab[GPIO0][28].alt_nb = GPIO_ALT2;
  1426. gpio_tab[GPIO0][29].in_out = GPIO_OUT; /* USB2D_PAD_SUSPNDM */
  1427. gpio_tab[GPIO0][29].alt_nb = GPIO_ALT2;
  1428. gpio_tab[GPIO0][30].in_out = GPIO_OUT; /* USB2D_XCVRSELECT */
  1429. gpio_tab[GPIO0][30].alt_nb = GPIO_ALT2;
  1430. gpio_tab[GPIO0][31].in_out = GPIO_OUT; /* USB2D_TERMSELECT */
  1431. gpio_tab[GPIO0][31].alt_nb = GPIO_ALT2;
  1432. gpio_tab[GPIO1][0].in_out = GPIO_OUT; /* USB2D_OPMODE0 */
  1433. gpio_tab[GPIO1][0].alt_nb = GPIO_ALT1;
  1434. gpio_tab[GPIO1][1].in_out = GPIO_OUT; /* USB2D_OPMODE1 */
  1435. gpio_tab[GPIO1][1].alt_nb = GPIO_ALT1;
  1436. }
  1437. /*----------------------------------------------------------------------------+
  1438. | update_pci_patch_ios().
  1439. +----------------------------------------------------------------------------*/
  1440. void update_pci_patch_ios(void)
  1441. {
  1442. gpio_tab[GPIO0][29].in_out = GPIO_OUT; /* EBC_EXT_HDLA */
  1443. gpio_tab[GPIO0][29].alt_nb = GPIO_ALT1;
  1444. }
  1445. /*----------------------------------------------------------------------------+
  1446. | set_chip_gpio_configuration(unsigned char gpio_core)
  1447. | Put the core impacted by clock modification and sharing in reset.
  1448. | Config the select registers to resolve the sharing depending of the config.
  1449. | Configure the GPIO registers.
  1450. |
  1451. +----------------------------------------------------------------------------*/
  1452. void set_chip_gpio_configuration(unsigned char gpio_core)
  1453. {
  1454. unsigned char i=0, j=0, reg_offset = 0;
  1455. unsigned long gpio_reg, gpio_core_add;
  1456. /* GPIO config of the GPIOs 0 to 31 */
  1457. for (i=0; i<GPIO_MAX; i++, j++)
  1458. {
  1459. if (i == GPIO_MAX/2)
  1460. {
  1461. reg_offset = 4;
  1462. j = i-16;
  1463. }
  1464. gpio_core_add = gpio_tab[gpio_core][i].add;
  1465. if ( (gpio_tab[gpio_core][i].in_out == GPIO_IN) ||
  1466. (gpio_tab[gpio_core][i].in_out == GPIO_BI ))
  1467. {
  1468. switch (gpio_tab[gpio_core][i].alt_nb)
  1469. {
  1470. case GPIO_SEL:
  1471. break;
  1472. case GPIO_ALT1:
  1473. gpio_reg = in32(GPIO_IS1(gpio_core_add+reg_offset)) & ~(GPIO_MASK >> (j*2));
  1474. gpio_reg = gpio_reg | (GPIO_IN_SEL >> (j*2));
  1475. out32(GPIO_IS1(gpio_core_add+reg_offset), gpio_reg);
  1476. break;
  1477. case GPIO_ALT2:
  1478. gpio_reg = in32(GPIO_IS2(gpio_core_add+reg_offset)) & ~(GPIO_MASK >> (j*2));
  1479. gpio_reg = gpio_reg | (GPIO_IN_SEL >> (j*2));
  1480. out32(GPIO_IS2(gpio_core_add+reg_offset), gpio_reg);
  1481. break;
  1482. case GPIO_ALT3:
  1483. gpio_reg = in32(GPIO_IS3(gpio_core_add+reg_offset)) & ~(GPIO_MASK >> (j*2));
  1484. gpio_reg = gpio_reg | (GPIO_IN_SEL >> (j*2));
  1485. out32(GPIO_IS3(gpio_core_add+reg_offset), gpio_reg);
  1486. break;
  1487. }
  1488. }
  1489. if ( (gpio_tab[gpio_core][i].in_out == GPIO_OUT) ||
  1490. (gpio_tab[gpio_core][i].in_out == GPIO_BI ))
  1491. {
  1492. switch (gpio_tab[gpio_core][i].alt_nb)
  1493. {
  1494. case GPIO_SEL:
  1495. break;
  1496. case GPIO_ALT1:
  1497. gpio_reg = in32(GPIO_OS(gpio_core_add+reg_offset)) & ~(GPIO_MASK >> (j*2));
  1498. gpio_reg = gpio_reg | (GPIO_ALT1_SEL >> (j*2));
  1499. out32(GPIO_OS(gpio_core_add+reg_offset), gpio_reg);
  1500. gpio_reg = in32(GPIO_TS(gpio_core_add+reg_offset)) & ~(GPIO_MASK >> (j*2));
  1501. gpio_reg = gpio_reg | (GPIO_ALT1_SEL >> (j*2));
  1502. out32(GPIO_TS(gpio_core_add+reg_offset), gpio_reg);
  1503. break;
  1504. case GPIO_ALT2:
  1505. gpio_reg = in32(GPIO_OS(gpio_core_add+reg_offset)) & ~(GPIO_MASK >> (j*2));
  1506. gpio_reg = gpio_reg | (GPIO_ALT2_SEL >> (j*2));
  1507. out32(GPIO_OS(gpio_core_add+reg_offset), gpio_reg);
  1508. gpio_reg = in32(GPIO_TS(gpio_core_add+reg_offset)) & ~(GPIO_MASK >> (j*2));
  1509. gpio_reg = gpio_reg | (GPIO_ALT2_SEL >> (j*2));
  1510. out32(GPIO_TS(gpio_core_add+reg_offset), gpio_reg);
  1511. break;
  1512. case GPIO_ALT3:
  1513. gpio_reg = in32(GPIO_OS(gpio_core_add+reg_offset)) & ~(GPIO_MASK >> (j*2));
  1514. gpio_reg = gpio_reg | (GPIO_ALT3_SEL >> (j*2));
  1515. out32(GPIO_OS(gpio_core_add+reg_offset), gpio_reg);
  1516. gpio_reg = in32(GPIO_TS(gpio_core_add+reg_offset)) & ~(GPIO_MASK >> (j*2));
  1517. gpio_reg = gpio_reg | (GPIO_ALT3_SEL >> (j*2));
  1518. out32(GPIO_TS(gpio_core_add+reg_offset), gpio_reg);
  1519. break;
  1520. }
  1521. }
  1522. }
  1523. }
  1524. /*----------------------------------------------------------------------------+
  1525. | force_bup_core_selection.
  1526. +----------------------------------------------------------------------------*/
  1527. void force_bup_core_selection(core_selection_t *core_select_P, config_validity_t *config_val_P)
  1528. {
  1529. /* Pointer invalid */
  1530. if (core_select_P == NULL)
  1531. {
  1532. printf("Configuration invalid pointer 1\n");
  1533. for (;;)
  1534. ;
  1535. }
  1536. /* L4 Selection */
  1537. *(core_select_P+UART_CORE0) = CORE_SELECTED;
  1538. *(core_select_P+UART_CORE1) = CORE_SELECTED;
  1539. *(core_select_P+UART_CORE2) = CORE_SELECTED;
  1540. *(core_select_P+UART_CORE3) = CORE_SELECTED;
  1541. /* RMII Selection */
  1542. *(core_select_P+RMII_SEL) = CORE_SELECTED;
  1543. /* External Interrupt 0-9 selection */
  1544. *(core_select_P+UIC_0_3) = CORE_SELECTED;
  1545. *(core_select_P+UIC_4_9) = CORE_SELECTED;
  1546. *(core_select_P+SCP_CORE) = CORE_SELECTED;
  1547. *(core_select_P+DMA_CHANNEL_CD) = CORE_SELECTED;
  1548. *(core_select_P+PACKET_REJ_FUNC_AVAIL) = CORE_SELECTED;
  1549. *(core_select_P+USB1_DEVICE) = CORE_SELECTED;
  1550. if (is_nand_selected()) {
  1551. *(core_select_P+NAND_FLASH) = CORE_SELECTED;
  1552. }
  1553. *config_val_P = CONFIG_IS_VALID;
  1554. }
  1555. /*----------------------------------------------------------------------------+
  1556. | configure_ppc440ep_pins.
  1557. +----------------------------------------------------------------------------*/
  1558. void configure_ppc440ep_pins(void)
  1559. {
  1560. uart_config_nb_t uart_configuration;
  1561. config_validity_t config_val = CONFIG_IS_INVALID;
  1562. /* Create Core Selection Table */
  1563. core_selection_t ppc440ep_core_selection[MAX_CORE_SELECT_NB] =
  1564. {
  1565. CORE_NOT_SELECTED, /* IIC_CORE, */
  1566. CORE_NOT_SELECTED, /* SPC_CORE, */
  1567. CORE_NOT_SELECTED, /* DMA_CHANNEL_AB, */
  1568. CORE_NOT_SELECTED, /* UIC_4_9, */
  1569. CORE_NOT_SELECTED, /* USB2_HOST, */
  1570. CORE_NOT_SELECTED, /* DMA_CHANNEL_CD, */
  1571. CORE_NOT_SELECTED, /* USB2_DEVICE, */
  1572. CORE_NOT_SELECTED, /* PACKET_REJ_FUNC_AVAIL, */
  1573. CORE_NOT_SELECTED, /* USB1_DEVICE, */
  1574. CORE_NOT_SELECTED, /* EBC_MASTER, */
  1575. CORE_NOT_SELECTED, /* NAND_FLASH, */
  1576. CORE_NOT_SELECTED, /* UART_CORE0, */
  1577. CORE_NOT_SELECTED, /* UART_CORE1, */
  1578. CORE_NOT_SELECTED, /* UART_CORE2, */
  1579. CORE_NOT_SELECTED, /* UART_CORE3, */
  1580. CORE_NOT_SELECTED, /* MII_SEL, */
  1581. CORE_NOT_SELECTED, /* RMII_SEL, */
  1582. CORE_NOT_SELECTED, /* SMII_SEL, */
  1583. CORE_NOT_SELECTED, /* PACKET_REJ_FUNC_EN */
  1584. CORE_NOT_SELECTED, /* UIC_0_3 */
  1585. CORE_NOT_SELECTED, /* USB1_HOST */
  1586. CORE_NOT_SELECTED /* PCI_PATCH */
  1587. };
  1588. /* Table Default Initialisation + FPGA Access */
  1589. init_default_gpio();
  1590. set_chip_gpio_configuration(GPIO0);
  1591. set_chip_gpio_configuration(GPIO1);
  1592. /* Update Table */
  1593. force_bup_core_selection(ppc440ep_core_selection, &config_val);
  1594. #if 0 /* test-only */
  1595. /* If we are running PIBS 1, force known configuration */
  1596. update_core_selection_table(ppc440ep_core_selection, &config_val);
  1597. #endif
  1598. /*----------------------------------------------------------------------------+
  1599. | SDR + ios table update + fpga initialization
  1600. +----------------------------------------------------------------------------*/
  1601. unsigned long sdr0_pfc1 = 0;
  1602. unsigned long sdr0_usb0 = 0;
  1603. unsigned long sdr0_mfr = 0;
  1604. /* PCI Always selected */
  1605. /* I2C Selection */
  1606. if (ppc440ep_core_selection[IIC_CORE] == CORE_SELECTED)
  1607. {
  1608. sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_SIS_MASK) | SDR0_PFC1_SIS_IIC1_SEL;
  1609. iic1_selection_in_fpga();
  1610. }
  1611. /* SCP Selection */
  1612. if (ppc440ep_core_selection[SCP_CORE] == CORE_SELECTED)
  1613. {
  1614. sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_SIS_MASK) | SDR0_PFC1_SIS_SCP_SEL;
  1615. scp_selection_in_fpga();
  1616. }
  1617. /* UIC 0:3 Selection */
  1618. if (ppc440ep_core_selection[UIC_0_3] == CORE_SELECTED)
  1619. {
  1620. update_uic_0_3_irq_ios();
  1621. dma_a_b_unselect_in_fpga();
  1622. }
  1623. /* UIC 4:9 Selection */
  1624. if (ppc440ep_core_selection[UIC_4_9] == CORE_SELECTED)
  1625. {
  1626. sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_DIS_MASK) | SDR0_PFC1_DIS_UICIRQ5_SEL;
  1627. update_uic_4_9_irq_ios();
  1628. }
  1629. /* DMA AB Selection */
  1630. if (ppc440ep_core_selection[DMA_CHANNEL_AB] == CORE_SELECTED)
  1631. {
  1632. sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_DIS_MASK) | SDR0_PFC1_DIS_DMAR_SEL;
  1633. update_dma_a_b_ios();
  1634. dma_a_b_selection_in_fpga();
  1635. }
  1636. /* DMA CD Selection */
  1637. if (ppc440ep_core_selection[DMA_CHANNEL_CD] == CORE_SELECTED)
  1638. {
  1639. update_dma_c_d_ios();
  1640. dma_c_d_selection_in_fpga();
  1641. }
  1642. /* EBC Master Selection */
  1643. if (ppc440ep_core_selection[EBC_MASTER] == CORE_SELECTED)
  1644. {
  1645. sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_ERE_MASK) | SDR0_PFC1_ERE_EXTR_SEL;
  1646. sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_UES_MASK) | SDR0_PFC1_UES_EBCHR_SEL;
  1647. update_ebc_master_ios();
  1648. }
  1649. /* PCI Patch Enable */
  1650. if (ppc440ep_core_selection[PCI_PATCH] == CORE_SELECTED)
  1651. {
  1652. sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_UES_MASK) | SDR0_PFC1_UES_EBCHR_SEL;
  1653. update_pci_patch_ios();
  1654. }
  1655. /* USB2 Host Selection - Not Implemented in PowerPC 440EP Pass1 */
  1656. if (ppc440ep_core_selection[USB2_HOST] == CORE_SELECTED)
  1657. {
  1658. /* Not Implemented in PowerPC 440EP Pass1-Pass2 */
  1659. printf("Invalid configuration => USB2 Host selected\n");
  1660. for (;;)
  1661. ;
  1662. /*usb2_host_selection_in_fpga(); */
  1663. }
  1664. /* USB2.0 Device Selection */
  1665. if (ppc440ep_core_selection[USB2_DEVICE] == CORE_SELECTED)
  1666. {
  1667. update_usb2_device_ios();
  1668. sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_UES_MASK) | SDR0_PFC1_UES_USB2D_SEL;
  1669. sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_UPR_MASK) | SDR0_PFC1_UPR_DISABLE;
  1670. mfsdr(sdr_usb0, sdr0_usb0);
  1671. sdr0_usb0 = sdr0_usb0 &~SDR0_USB0_USB_DEVSEL_MASK;
  1672. sdr0_usb0 = sdr0_usb0 | SDR0_USB0_USB20D_DEVSEL;
  1673. mtsdr(sdr_usb0, sdr0_usb0);
  1674. usb2_device_selection_in_fpga();
  1675. }
  1676. /* USB1.1 Device Selection */
  1677. if (ppc440ep_core_selection[USB1_DEVICE] == CORE_SELECTED)
  1678. {
  1679. mfsdr(sdr_usb0, sdr0_usb0);
  1680. sdr0_usb0 = sdr0_usb0 &~SDR0_USB0_USB_DEVSEL_MASK;
  1681. sdr0_usb0 = sdr0_usb0 | SDR0_USB0_USB11D_DEVSEL;
  1682. mtsdr(sdr_usb0, sdr0_usb0);
  1683. }
  1684. /* USB1.1 Host Selection */
  1685. if (ppc440ep_core_selection[USB1_HOST] == CORE_SELECTED)
  1686. {
  1687. mfsdr(sdr_usb0, sdr0_usb0);
  1688. sdr0_usb0 = sdr0_usb0 &~SDR0_USB0_LEEN_MASK;
  1689. sdr0_usb0 = sdr0_usb0 | SDR0_USB0_LEEN_ENABLE;
  1690. mtsdr(sdr_usb0, sdr0_usb0);
  1691. }
  1692. /* NAND Flash Selection */
  1693. if (ppc440ep_core_selection[NAND_FLASH] == CORE_SELECTED)
  1694. {
  1695. update_ndfc_ios();
  1696. mtsdr(sdr_cust0, SDR0_CUST0_MUX_NDFC_SEL |
  1697. SDR0_CUST0_NDFC_ENABLE |
  1698. SDR0_CUST0_NDFC_BW_8_BIT |
  1699. SDR0_CUST0_NDFC_ARE_MASK |
  1700. SDR0_CUST0_CHIPSELGAT_EN1 |
  1701. SDR0_CUST0_CHIPSELGAT_EN2);
  1702. ndfc_selection_in_fpga();
  1703. }
  1704. else
  1705. {
  1706. /* Set Mux on EMAC */
  1707. mtsdr(sdr_cust0, SDR0_CUST0_MUX_EMAC_SEL);
  1708. }
  1709. /* MII Selection */
  1710. if (ppc440ep_core_selection[MII_SEL] == CORE_SELECTED)
  1711. {
  1712. update_zii_ios();
  1713. mfsdr(sdr_mfr, sdr0_mfr);
  1714. sdr0_mfr = (sdr0_mfr & ~SDR0_MFR_ZMII_MODE_MASK) | SDR0_MFR_ZMII_MODE_MII;
  1715. mtsdr(sdr_mfr, sdr0_mfr);
  1716. set_phy_configuration_through_fpga(ZMII_CONFIGURATION_IS_MII);
  1717. }
  1718. /* RMII Selection */
  1719. if (ppc440ep_core_selection[RMII_SEL] == CORE_SELECTED)
  1720. {
  1721. update_zii_ios();
  1722. mfsdr(sdr_mfr, sdr0_mfr);
  1723. sdr0_mfr = (sdr0_mfr & ~SDR0_MFR_ZMII_MODE_MASK) | SDR0_MFR_ZMII_MODE_RMII_10M;
  1724. mtsdr(sdr_mfr, sdr0_mfr);
  1725. set_phy_configuration_through_fpga(ZMII_CONFIGURATION_IS_RMII);
  1726. }
  1727. /* SMII Selection */
  1728. if (ppc440ep_core_selection[SMII_SEL] == CORE_SELECTED)
  1729. {
  1730. update_zii_ios();
  1731. mfsdr(sdr_mfr, sdr0_mfr);
  1732. sdr0_mfr = (sdr0_mfr & ~SDR0_MFR_ZMII_MODE_MASK) | SDR0_MFR_ZMII_MODE_SMII;
  1733. mtsdr(sdr_mfr, sdr0_mfr);
  1734. set_phy_configuration_through_fpga(ZMII_CONFIGURATION_IS_SMII);
  1735. }
  1736. /* UART Selection */
  1737. uart_configuration = get_uart_configuration();
  1738. switch (uart_configuration)
  1739. {
  1740. case L1: /* L1 Selection */
  1741. /* UART0 8 pins Only */
  1742. /*sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_U0ME_MASK) | SDR0_PFC1_U0ME_DSR_DTR; */
  1743. sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_U0ME_MASK) |SDR0_PFC1_U0ME_CTS_RTS; /* Chip Pb */
  1744. sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_U0IM_MASK) | SDR0_PFC1_U0IM_8PINS;
  1745. break;
  1746. case L2: /* L2 Selection */
  1747. /* UART0 and UART1 4 pins */
  1748. sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_U0ME_MASK) | SDR0_PFC1_U1ME_DSR_DTR;
  1749. sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_U0IM_MASK) | SDR0_PFC1_U0IM_4PINS;
  1750. sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_U1ME_MASK) | SDR0_PFC1_U1ME_DSR_DTR;
  1751. break;
  1752. case L3: /* L3 Selection */
  1753. /* UART0 4 pins, UART1 and UART2 2 pins */
  1754. sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_U0ME_MASK) | SDR0_PFC1_U1ME_DSR_DTR;
  1755. sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_U0IM_MASK) | SDR0_PFC1_U0IM_4PINS;
  1756. sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_U1ME_MASK) | SDR0_PFC1_U1ME_DSR_DTR;
  1757. break;
  1758. case L4: /* L4 Selection */
  1759. /* UART0, UART1, UART2 and UART3 2 pins */
  1760. sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_U0ME_MASK) | SDR0_PFC1_U0ME_DSR_DTR;
  1761. sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_U0IM_MASK) | SDR0_PFC1_U0IM_4PINS;
  1762. sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_U1ME_MASK) | SDR0_PFC1_U1ME_DSR_DTR;
  1763. break;
  1764. }
  1765. update_uart_ios(uart_configuration);
  1766. /* UART Selection in all cases */
  1767. uart_selection_in_fpga(uart_configuration);
  1768. /* Packet Reject Function Available */
  1769. if (ppc440ep_core_selection[PACKET_REJ_FUNC_AVAIL] == CORE_SELECTED)
  1770. {
  1771. /* Set UPR Bit in SDR0_PFC1 Register */
  1772. sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_UPR_MASK) | SDR0_PFC1_UPR_ENABLE;
  1773. }
  1774. /* Packet Reject Function Enable */
  1775. if (ppc440ep_core_selection[PACKET_REJ_FUNC_EN] == CORE_SELECTED)
  1776. {
  1777. mfsdr(sdr_mfr, sdr0_mfr);
  1778. sdr0_mfr = (sdr0_mfr & ~SDR0_MFR_PKT_REJ_MASK) | SDR0_MFR_PKT_REJ_EN;;
  1779. mtsdr(sdr_mfr, sdr0_mfr);
  1780. }
  1781. /* Perform effective access to hardware */
  1782. mtsdr(sdr_pfc1, sdr0_pfc1);
  1783. set_chip_gpio_configuration(GPIO0);
  1784. set_chip_gpio_configuration(GPIO1);
  1785. /* USB2.0 Device Reset must be done after GPIO setting */
  1786. if (ppc440ep_core_selection[USB2_DEVICE] == CORE_SELECTED)
  1787. usb2_device_reset_through_fpga();
  1788. }