mv64x60.c 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391
  1. /*
  2. * arch/ppc/syslib/mv64x60.c
  3. *
  4. * Common routines for the Marvell/Galileo Discovery line of host bridges
  5. * (gt64260, mv64360, mv64460, ...).
  6. *
  7. * Author: Mark A. Greer <mgreer@mvista.com>
  8. *
  9. * 2004 (c) MontaVista, Software, Inc. This file is licensed under
  10. * the terms of the GNU General Public License version 2. This program
  11. * is licensed "as is" without any warranty of any kind, whether express
  12. * or implied.
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/init.h>
  16. #include <linux/pci.h>
  17. #include <linux/slab.h>
  18. #include <linux/module.h>
  19. #include <linux/string.h>
  20. #include <linux/spinlock.h>
  21. #include <linux/mv643xx.h>
  22. #include <asm/byteorder.h>
  23. #include <asm/io.h>
  24. #include <asm/irq.h>
  25. #include <asm/uaccess.h>
  26. #include <asm/machdep.h>
  27. #include <asm/pci-bridge.h>
  28. #include <asm/delay.h>
  29. #include <asm/mv64x60.h>
  30. u8 mv64x60_pci_exclude_bridge = 1;
  31. spinlock_t mv64x60_lock = SPIN_LOCK_UNLOCKED;
  32. static phys_addr_t mv64x60_bridge_pbase = 0;
  33. static void *mv64x60_bridge_vbase = 0;
  34. static u32 mv64x60_bridge_type = MV64x60_TYPE_INVALID;
  35. static u32 mv64x60_bridge_rev = 0;
  36. static u32 gt64260_translate_size(u32 base, u32 size, u32 num_bits);
  37. static u32 gt64260_untranslate_size(u32 base, u32 size, u32 num_bits);
  38. static void gt64260_set_pci2mem_window(struct pci_controller *hose, u32 bus,
  39. u32 window, u32 base);
  40. static void gt64260_set_pci2regs_window(struct mv64x60_handle *bh,
  41. struct pci_controller *hose, u32 bus, u32 base);
  42. static u32 gt64260_is_enabled_32bit(struct mv64x60_handle *bh, u32 window);
  43. static void gt64260_enable_window_32bit(struct mv64x60_handle *bh, u32 window);
  44. static void gt64260_disable_window_32bit(struct mv64x60_handle *bh, u32 window);
  45. static void gt64260_enable_window_64bit(struct mv64x60_handle *bh, u32 window);
  46. static void gt64260_disable_window_64bit(struct mv64x60_handle *bh, u32 window);
  47. static void gt64260_disable_all_windows(struct mv64x60_handle *bh,
  48. struct mv64x60_setup_info *si);
  49. static void gt64260a_chip_specific_init(struct mv64x60_handle *bh,
  50. struct mv64x60_setup_info *si);
  51. static void gt64260b_chip_specific_init(struct mv64x60_handle *bh,
  52. struct mv64x60_setup_info *si);
  53. static u32 mv64360_translate_size(u32 base, u32 size, u32 num_bits);
  54. static u32 mv64360_untranslate_size(u32 base, u32 size, u32 num_bits);
  55. static void mv64360_set_pci2mem_window(struct pci_controller *hose, u32 bus,
  56. u32 window, u32 base);
  57. static void mv64360_set_pci2regs_window(struct mv64x60_handle *bh,
  58. struct pci_controller *hose, u32 bus, u32 base);
  59. static u32 mv64360_is_enabled_32bit(struct mv64x60_handle *bh, u32 window);
  60. static void mv64360_enable_window_32bit(struct mv64x60_handle *bh, u32 window);
  61. static void mv64360_disable_window_32bit(struct mv64x60_handle *bh, u32 window);
  62. static void mv64360_enable_window_64bit(struct mv64x60_handle *bh, u32 window);
  63. static void mv64360_disable_window_64bit(struct mv64x60_handle *bh, u32 window);
  64. static void mv64360_disable_all_windows(struct mv64x60_handle *bh,
  65. struct mv64x60_setup_info *si);
  66. static void mv64360_config_io2mem_windows(struct mv64x60_handle *bh,
  67. struct mv64x60_setup_info *si,
  68. u32 mem_windows[MV64x60_CPU2MEM_WINDOWS][2]);
  69. static void mv64360_set_mpsc2regs_window(struct mv64x60_handle *bh, u32 base);
  70. static void mv64360_chip_specific_init(struct mv64x60_handle *bh,
  71. struct mv64x60_setup_info *si);
  72. static void mv64460_chip_specific_init(struct mv64x60_handle *bh,
  73. struct mv64x60_setup_info *si);
  74. /*
  75. * Define tables that have the chip-specific info for each type of
  76. * Marvell bridge chip.
  77. */
  78. static struct mv64x60_chip_info gt64260a_ci __initdata = { /* GT64260A */
  79. .translate_size = gt64260_translate_size,
  80. .untranslate_size = gt64260_untranslate_size,
  81. .set_pci2mem_window = gt64260_set_pci2mem_window,
  82. .set_pci2regs_window = gt64260_set_pci2regs_window,
  83. .is_enabled_32bit = gt64260_is_enabled_32bit,
  84. .enable_window_32bit = gt64260_enable_window_32bit,
  85. .disable_window_32bit = gt64260_disable_window_32bit,
  86. .enable_window_64bit = gt64260_enable_window_64bit,
  87. .disable_window_64bit = gt64260_disable_window_64bit,
  88. .disable_all_windows = gt64260_disable_all_windows,
  89. .chip_specific_init = gt64260a_chip_specific_init,
  90. .window_tab_32bit = gt64260_32bit_windows,
  91. .window_tab_64bit = gt64260_64bit_windows,
  92. };
  93. static struct mv64x60_chip_info gt64260b_ci __initdata = { /* GT64260B */
  94. .translate_size = gt64260_translate_size,
  95. .untranslate_size = gt64260_untranslate_size,
  96. .set_pci2mem_window = gt64260_set_pci2mem_window,
  97. .set_pci2regs_window = gt64260_set_pci2regs_window,
  98. .is_enabled_32bit = gt64260_is_enabled_32bit,
  99. .enable_window_32bit = gt64260_enable_window_32bit,
  100. .disable_window_32bit = gt64260_disable_window_32bit,
  101. .enable_window_64bit = gt64260_enable_window_64bit,
  102. .disable_window_64bit = gt64260_disable_window_64bit,
  103. .disable_all_windows = gt64260_disable_all_windows,
  104. .chip_specific_init = gt64260b_chip_specific_init,
  105. .window_tab_32bit = gt64260_32bit_windows,
  106. .window_tab_64bit = gt64260_64bit_windows,
  107. };
  108. static struct mv64x60_chip_info mv64360_ci __initdata = { /* MV64360 */
  109. .translate_size = mv64360_translate_size,
  110. .untranslate_size = mv64360_untranslate_size,
  111. .set_pci2mem_window = mv64360_set_pci2mem_window,
  112. .set_pci2regs_window = mv64360_set_pci2regs_window,
  113. .is_enabled_32bit = mv64360_is_enabled_32bit,
  114. .enable_window_32bit = mv64360_enable_window_32bit,
  115. .disable_window_32bit = mv64360_disable_window_32bit,
  116. .enable_window_64bit = mv64360_enable_window_64bit,
  117. .disable_window_64bit = mv64360_disable_window_64bit,
  118. .disable_all_windows = mv64360_disable_all_windows,
  119. .config_io2mem_windows = mv64360_config_io2mem_windows,
  120. .set_mpsc2regs_window = mv64360_set_mpsc2regs_window,
  121. .chip_specific_init = mv64360_chip_specific_init,
  122. .window_tab_32bit = mv64360_32bit_windows,
  123. .window_tab_64bit = mv64360_64bit_windows,
  124. };
  125. static struct mv64x60_chip_info mv64460_ci __initdata = { /* MV64460 */
  126. .translate_size = mv64360_translate_size,
  127. .untranslate_size = mv64360_untranslate_size,
  128. .set_pci2mem_window = mv64360_set_pci2mem_window,
  129. .set_pci2regs_window = mv64360_set_pci2regs_window,
  130. .is_enabled_32bit = mv64360_is_enabled_32bit,
  131. .enable_window_32bit = mv64360_enable_window_32bit,
  132. .disable_window_32bit = mv64360_disable_window_32bit,
  133. .enable_window_64bit = mv64360_enable_window_64bit,
  134. .disable_window_64bit = mv64360_disable_window_64bit,
  135. .disable_all_windows = mv64360_disable_all_windows,
  136. .config_io2mem_windows = mv64360_config_io2mem_windows,
  137. .set_mpsc2regs_window = mv64360_set_mpsc2regs_window,
  138. .chip_specific_init = mv64460_chip_specific_init,
  139. .window_tab_32bit = mv64360_32bit_windows,
  140. .window_tab_64bit = mv64360_64bit_windows,
  141. };
  142. /*
  143. *****************************************************************************
  144. *
  145. * Platform Device Definitions
  146. *
  147. *****************************************************************************
  148. */
  149. #ifdef CONFIG_SERIAL_MPSC
  150. static struct mpsc_shared_pdata mv64x60_mpsc_shared_pdata = {
  151. .mrr_val = 0x3ffffe38,
  152. .rcrr_val = 0,
  153. .tcrr_val = 0,
  154. .intr_cause_val = 0,
  155. .intr_mask_val = 0,
  156. };
  157. static struct resource mv64x60_mpsc_shared_resources[] = {
  158. /* Do not change the order of the IORESOURCE_MEM resources */
  159. [0] = {
  160. .name = "mpsc routing base",
  161. .start = MV64x60_MPSC_ROUTING_OFFSET,
  162. .end = MV64x60_MPSC_ROUTING_OFFSET +
  163. MPSC_ROUTING_REG_BLOCK_SIZE - 1,
  164. .flags = IORESOURCE_MEM,
  165. },
  166. [1] = {
  167. .name = "sdma intr base",
  168. .start = MV64x60_SDMA_INTR_OFFSET,
  169. .end = MV64x60_SDMA_INTR_OFFSET +
  170. MPSC_SDMA_INTR_REG_BLOCK_SIZE - 1,
  171. .flags = IORESOURCE_MEM,
  172. },
  173. };
  174. static struct platform_device mpsc_shared_device = { /* Shared device */
  175. .name = MPSC_SHARED_NAME,
  176. .id = 0,
  177. .num_resources = ARRAY_SIZE(mv64x60_mpsc_shared_resources),
  178. .resource = mv64x60_mpsc_shared_resources,
  179. .dev = {
  180. .platform_data = &mv64x60_mpsc_shared_pdata,
  181. },
  182. };
  183. static struct mpsc_pdata mv64x60_mpsc0_pdata = {
  184. .mirror_regs = 0,
  185. .cache_mgmt = 0,
  186. .max_idle = 0,
  187. .default_baud = 9600,
  188. .default_bits = 8,
  189. .default_parity = 'n',
  190. .default_flow = 'n',
  191. .chr_1_val = 0x00000000,
  192. .chr_2_val = 0x00000000,
  193. .chr_10_val = 0x00000003,
  194. .mpcr_val = 0,
  195. .bcr_val = 0,
  196. .brg_can_tune = 0,
  197. .brg_clk_src = 8, /* Default to TCLK */
  198. .brg_clk_freq = 100000000, /* Default to 100 MHz */
  199. };
  200. static struct resource mv64x60_mpsc0_resources[] = {
  201. /* Do not change the order of the IORESOURCE_MEM resources */
  202. [0] = {
  203. .name = "mpsc 0 base",
  204. .start = MV64x60_MPSC_0_OFFSET,
  205. .end = MV64x60_MPSC_0_OFFSET + MPSC_REG_BLOCK_SIZE - 1,
  206. .flags = IORESOURCE_MEM,
  207. },
  208. [1] = {
  209. .name = "sdma 0 base",
  210. .start = MV64x60_SDMA_0_OFFSET,
  211. .end = MV64x60_SDMA_0_OFFSET + MPSC_SDMA_REG_BLOCK_SIZE - 1,
  212. .flags = IORESOURCE_MEM,
  213. },
  214. [2] = {
  215. .name = "brg 0 base",
  216. .start = MV64x60_BRG_0_OFFSET,
  217. .end = MV64x60_BRG_0_OFFSET + MPSC_BRG_REG_BLOCK_SIZE - 1,
  218. .flags = IORESOURCE_MEM,
  219. },
  220. [3] = {
  221. .name = "sdma 0 irq",
  222. .start = MV64x60_IRQ_SDMA_0,
  223. .end = MV64x60_IRQ_SDMA_0,
  224. .flags = IORESOURCE_IRQ,
  225. },
  226. };
  227. static struct platform_device mpsc0_device = {
  228. .name = MPSC_CTLR_NAME,
  229. .id = 0,
  230. .num_resources = ARRAY_SIZE(mv64x60_mpsc0_resources),
  231. .resource = mv64x60_mpsc0_resources,
  232. .dev = {
  233. .platform_data = &mv64x60_mpsc0_pdata,
  234. },
  235. };
  236. static struct mpsc_pdata mv64x60_mpsc1_pdata = {
  237. .mirror_regs = 0,
  238. .cache_mgmt = 0,
  239. .max_idle = 0,
  240. .default_baud = 9600,
  241. .default_bits = 8,
  242. .default_parity = 'n',
  243. .default_flow = 'n',
  244. .chr_1_val = 0x00000000,
  245. .chr_1_val = 0x00000000,
  246. .chr_2_val = 0x00000000,
  247. .chr_10_val = 0x00000003,
  248. .mpcr_val = 0,
  249. .bcr_val = 0,
  250. .brg_can_tune = 0,
  251. .brg_clk_src = 8, /* Default to TCLK */
  252. .brg_clk_freq = 100000000, /* Default to 100 MHz */
  253. };
  254. static struct resource mv64x60_mpsc1_resources[] = {
  255. /* Do not change the order of the IORESOURCE_MEM resources */
  256. [0] = {
  257. .name = "mpsc 1 base",
  258. .start = MV64x60_MPSC_1_OFFSET,
  259. .end = MV64x60_MPSC_1_OFFSET + MPSC_REG_BLOCK_SIZE - 1,
  260. .flags = IORESOURCE_MEM,
  261. },
  262. [1] = {
  263. .name = "sdma 1 base",
  264. .start = MV64x60_SDMA_1_OFFSET,
  265. .end = MV64x60_SDMA_1_OFFSET + MPSC_SDMA_REG_BLOCK_SIZE - 1,
  266. .flags = IORESOURCE_MEM,
  267. },
  268. [2] = {
  269. .name = "brg 1 base",
  270. .start = MV64x60_BRG_1_OFFSET,
  271. .end = MV64x60_BRG_1_OFFSET + MPSC_BRG_REG_BLOCK_SIZE - 1,
  272. .flags = IORESOURCE_MEM,
  273. },
  274. [3] = {
  275. .name = "sdma 1 irq",
  276. .start = MV64360_IRQ_SDMA_1,
  277. .end = MV64360_IRQ_SDMA_1,
  278. .flags = IORESOURCE_IRQ,
  279. },
  280. };
  281. static struct platform_device mpsc1_device = {
  282. .name = MPSC_CTLR_NAME,
  283. .id = 1,
  284. .num_resources = ARRAY_SIZE(mv64x60_mpsc1_resources),
  285. .resource = mv64x60_mpsc1_resources,
  286. .dev = {
  287. .platform_data = &mv64x60_mpsc1_pdata,
  288. },
  289. };
  290. #endif
  291. #ifdef CONFIG_MV643XX_ETH
  292. static struct resource mv64x60_eth_shared_resources[] = {
  293. [0] = {
  294. .name = "ethernet shared base",
  295. .start = MV643XX_ETH_SHARED_REGS,
  296. .end = MV643XX_ETH_SHARED_REGS +
  297. MV643XX_ETH_SHARED_REGS_SIZE - 1,
  298. .flags = IORESOURCE_MEM,
  299. },
  300. };
  301. static struct platform_device mv64x60_eth_shared_device = {
  302. .name = MV643XX_ETH_SHARED_NAME,
  303. .id = 0,
  304. .num_resources = ARRAY_SIZE(mv64x60_eth_shared_resources),
  305. .resource = mv64x60_eth_shared_resources,
  306. };
  307. #ifdef CONFIG_MV643XX_ETH_0
  308. static struct resource mv64x60_eth0_resources[] = {
  309. [0] = {
  310. .name = "eth0 irq",
  311. .start = MV64x60_IRQ_ETH_0,
  312. .end = MV64x60_IRQ_ETH_0,
  313. .flags = IORESOURCE_IRQ,
  314. },
  315. };
  316. static struct mv643xx_eth_platform_data eth0_pd;
  317. static struct platform_device eth0_device = {
  318. .name = MV643XX_ETH_NAME,
  319. .id = 0,
  320. .num_resources = ARRAY_SIZE(mv64x60_eth0_resources),
  321. .resource = mv64x60_eth0_resources,
  322. .dev = {
  323. .platform_data = &eth0_pd,
  324. },
  325. };
  326. #endif
  327. #ifdef CONFIG_MV643XX_ETH_1
  328. static struct resource mv64x60_eth1_resources[] = {
  329. [0] = {
  330. .name = "eth1 irq",
  331. .start = MV64x60_IRQ_ETH_1,
  332. .end = MV64x60_IRQ_ETH_1,
  333. .flags = IORESOURCE_IRQ,
  334. },
  335. };
  336. static struct mv643xx_eth_platform_data eth1_pd;
  337. static struct platform_device eth1_device = {
  338. .name = MV643XX_ETH_NAME,
  339. .id = 1,
  340. .num_resources = ARRAY_SIZE(mv64x60_eth1_resources),
  341. .resource = mv64x60_eth1_resources,
  342. .dev = {
  343. .platform_data = &eth1_pd,
  344. },
  345. };
  346. #endif
  347. #ifdef CONFIG_MV643XX_ETH_2
  348. static struct resource mv64x60_eth2_resources[] = {
  349. [0] = {
  350. .name = "eth2 irq",
  351. .start = MV64x60_IRQ_ETH_2,
  352. .end = MV64x60_IRQ_ETH_2,
  353. .flags = IORESOURCE_IRQ,
  354. },
  355. };
  356. static struct mv643xx_eth_platform_data eth2_pd;
  357. static struct platform_device eth2_device = {
  358. .name = MV643XX_ETH_NAME,
  359. .id = 2,
  360. .num_resources = ARRAY_SIZE(mv64x60_eth2_resources),
  361. .resource = mv64x60_eth2_resources,
  362. .dev = {
  363. .platform_data = &eth2_pd,
  364. },
  365. };
  366. #endif
  367. #endif
  368. #ifdef CONFIG_I2C_MV64XXX
  369. static struct mv64xxx_i2c_pdata mv64xxx_i2c_pdata = {
  370. .freq_m = 8,
  371. .freq_n = 3,
  372. .timeout = 1000, /* Default timeout of 1 second */
  373. .retries = 1,
  374. };
  375. static struct resource mv64xxx_i2c_resources[] = {
  376. /* Do not change the order of the IORESOURCE_MEM resources */
  377. [0] = {
  378. .name = "mv64xxx i2c base",
  379. .start = MV64XXX_I2C_OFFSET,
  380. .end = MV64XXX_I2C_OFFSET + MV64XXX_I2C_REG_BLOCK_SIZE - 1,
  381. .flags = IORESOURCE_MEM,
  382. },
  383. [1] = {
  384. .name = "mv64xxx i2c irq",
  385. .start = MV64x60_IRQ_I2C,
  386. .end = MV64x60_IRQ_I2C,
  387. .flags = IORESOURCE_IRQ,
  388. },
  389. };
  390. static struct platform_device i2c_device = {
  391. .name = MV64XXX_I2C_CTLR_NAME,
  392. .id = 0,
  393. .num_resources = ARRAY_SIZE(mv64xxx_i2c_resources),
  394. .resource = mv64xxx_i2c_resources,
  395. .dev = {
  396. .platform_data = &mv64xxx_i2c_pdata,
  397. },
  398. };
  399. #endif
  400. static struct platform_device *mv64x60_pd_devs[] __initdata = {
  401. #ifdef CONFIG_SERIAL_MPSC
  402. &mpsc_shared_device,
  403. &mpsc0_device,
  404. &mpsc1_device,
  405. #endif
  406. #ifdef CONFIG_MV643XX_ETH
  407. &mv64x60_eth_shared_device,
  408. #endif
  409. #ifdef CONFIG_MV643XX_ETH_0
  410. &eth0_device,
  411. #endif
  412. #ifdef CONFIG_MV643XX_ETH_1
  413. &eth1_device,
  414. #endif
  415. #ifdef CONFIG_MV643XX_ETH_2
  416. &eth2_device,
  417. #endif
  418. #ifdef CONFIG_I2C_MV64XXX
  419. &i2c_device,
  420. #endif
  421. };
  422. /*
  423. *****************************************************************************
  424. *
  425. * Bridge Initialization Routines
  426. *
  427. *****************************************************************************
  428. */
  429. /*
  430. * mv64x60_init()
  431. *
  432. * Initialze the bridge based on setting passed in via 'si'. The bridge
  433. * handle, 'bh', will be set so that it can be used to make subsequent
  434. * calls to routines in this file.
  435. */
  436. int __init
  437. mv64x60_init(struct mv64x60_handle *bh, struct mv64x60_setup_info *si)
  438. {
  439. u32 mem_windows[MV64x60_CPU2MEM_WINDOWS][2];
  440. if (ppc_md.progress)
  441. ppc_md.progress("mv64x60 initialization", 0x0);
  442. spin_lock_init(&mv64x60_lock);
  443. mv64x60_early_init(bh, si);
  444. if (mv64x60_get_type(bh) || mv64x60_setup_for_chip(bh)) {
  445. iounmap(bh->v_base);
  446. bh->v_base = 0;
  447. if (ppc_md.progress)
  448. ppc_md.progress("mv64x60_init: Can't determine chip",0);
  449. return -1;
  450. }
  451. bh->ci->disable_all_windows(bh, si);
  452. mv64x60_get_mem_windows(bh, mem_windows);
  453. mv64x60_config_cpu2mem_windows(bh, si, mem_windows);
  454. if (bh->ci->config_io2mem_windows)
  455. bh->ci->config_io2mem_windows(bh, si, mem_windows);
  456. if (bh->ci->set_mpsc2regs_window)
  457. bh->ci->set_mpsc2regs_window(bh, si->phys_reg_base);
  458. if (si->pci_1.enable_bus) {
  459. bh->io_base_b = (u32)ioremap(si->pci_1.pci_io.cpu_base,
  460. si->pci_1.pci_io.size);
  461. isa_io_base = bh->io_base_b;
  462. }
  463. if (si->pci_0.enable_bus) {
  464. bh->io_base_a = (u32)ioremap(si->pci_0.pci_io.cpu_base,
  465. si->pci_0.pci_io.size);
  466. isa_io_base = bh->io_base_a;
  467. mv64x60_alloc_hose(bh, MV64x60_PCI0_CONFIG_ADDR,
  468. MV64x60_PCI0_CONFIG_DATA, &bh->hose_a);
  469. mv64x60_config_resources(bh->hose_a, &si->pci_0, bh->io_base_a);
  470. mv64x60_config_pci_params(bh->hose_a, &si->pci_0);
  471. mv64x60_config_cpu2pci_windows(bh, &si->pci_0, 0);
  472. mv64x60_config_pci2mem_windows(bh, bh->hose_a, &si->pci_0, 0,
  473. mem_windows);
  474. bh->ci->set_pci2regs_window(bh, bh->hose_a, 0,
  475. si->phys_reg_base);
  476. }
  477. if (si->pci_1.enable_bus) {
  478. mv64x60_alloc_hose(bh, MV64x60_PCI1_CONFIG_ADDR,
  479. MV64x60_PCI1_CONFIG_DATA, &bh->hose_b);
  480. mv64x60_config_resources(bh->hose_b, &si->pci_1, bh->io_base_b);
  481. mv64x60_config_pci_params(bh->hose_b, &si->pci_1);
  482. mv64x60_config_cpu2pci_windows(bh, &si->pci_1, 1);
  483. mv64x60_config_pci2mem_windows(bh, bh->hose_b, &si->pci_1, 1,
  484. mem_windows);
  485. bh->ci->set_pci2regs_window(bh, bh->hose_b, 1,
  486. si->phys_reg_base);
  487. }
  488. bh->ci->chip_specific_init(bh, si);
  489. mv64x60_pd_fixup(bh, mv64x60_pd_devs, ARRAY_SIZE(mv64x60_pd_devs));
  490. return 0;
  491. }
  492. /*
  493. * mv64x60_early_init()
  494. *
  495. * Do some bridge work that must take place before we start messing with
  496. * the bridge for real.
  497. */
  498. void __init
  499. mv64x60_early_init(struct mv64x60_handle *bh, struct mv64x60_setup_info *si)
  500. {
  501. struct pci_controller hose_a, hose_b;
  502. memset(bh, 0, sizeof(*bh));
  503. bh->p_base = si->phys_reg_base;
  504. bh->v_base = ioremap(bh->p_base, MV64x60_INTERNAL_SPACE_SIZE);
  505. mv64x60_bridge_pbase = bh->p_base;
  506. mv64x60_bridge_vbase = bh->v_base;
  507. /* Assuming pci mode [reserved] bits 4:5 on 64260 are 0 */
  508. bh->pci_mode_a = mv64x60_read(bh, MV64x60_PCI0_MODE) &
  509. MV64x60_PCIMODE_MASK;
  510. bh->pci_mode_b = mv64x60_read(bh, MV64x60_PCI1_MODE) &
  511. MV64x60_PCIMODE_MASK;
  512. /* Need temporary hose structs to call mv64x60_set_bus() */
  513. memset(&hose_a, 0, sizeof(hose_a));
  514. memset(&hose_b, 0, sizeof(hose_b));
  515. setup_indirect_pci_nomap(&hose_a, bh->v_base + MV64x60_PCI0_CONFIG_ADDR,
  516. bh->v_base + MV64x60_PCI0_CONFIG_DATA);
  517. setup_indirect_pci_nomap(&hose_b, bh->v_base + MV64x60_PCI1_CONFIG_ADDR,
  518. bh->v_base + MV64x60_PCI1_CONFIG_DATA);
  519. bh->hose_a = &hose_a;
  520. bh->hose_b = &hose_b;
  521. mv64x60_set_bus(bh, 0, 0);
  522. mv64x60_set_bus(bh, 1, 0);
  523. bh->hose_a = NULL;
  524. bh->hose_b = NULL;
  525. /* Clear bit 0 of PCI addr decode control so PCI->CPU remap 1:1 */
  526. mv64x60_clr_bits(bh, MV64x60_PCI0_PCI_DECODE_CNTL, 0x00000001);
  527. mv64x60_clr_bits(bh, MV64x60_PCI1_PCI_DECODE_CNTL, 0x00000001);
  528. /* Bit 12 MUST be 0; set bit 27--don't auto-update cpu remap regs */
  529. mv64x60_clr_bits(bh, MV64x60_CPU_CONFIG, (1<<12));
  530. mv64x60_set_bits(bh, MV64x60_CPU_CONFIG, (1<<27));
  531. mv64x60_set_bits(bh, MV64x60_PCI0_TO_RETRY, 0xffff);
  532. mv64x60_set_bits(bh, MV64x60_PCI1_TO_RETRY, 0xffff);
  533. return;
  534. }
  535. /*
  536. *****************************************************************************
  537. *
  538. * Window Config Routines
  539. *
  540. *****************************************************************************
  541. */
  542. /*
  543. * mv64x60_get_32bit_window()
  544. *
  545. * Determine the base address and size of a 32-bit window on the bridge.
  546. */
  547. void __init
  548. mv64x60_get_32bit_window(struct mv64x60_handle *bh, u32 window,
  549. u32 *base, u32 *size)
  550. {
  551. u32 val, base_reg, size_reg, base_bits, size_bits;
  552. u32 (*get_from_field)(u32 val, u32 num_bits);
  553. base_reg = bh->ci->window_tab_32bit[window].base_reg;
  554. if (base_reg != 0) {
  555. size_reg = bh->ci->window_tab_32bit[window].size_reg;
  556. base_bits = bh->ci->window_tab_32bit[window].base_bits;
  557. size_bits = bh->ci->window_tab_32bit[window].size_bits;
  558. get_from_field= bh->ci->window_tab_32bit[window].get_from_field;
  559. val = mv64x60_read(bh, base_reg);
  560. *base = get_from_field(val, base_bits);
  561. if (size_reg != 0) {
  562. val = mv64x60_read(bh, size_reg);
  563. val = get_from_field(val, size_bits);
  564. *size = bh->ci->untranslate_size(*base, val, size_bits);
  565. }
  566. else
  567. *size = 0;
  568. }
  569. else {
  570. *base = 0;
  571. *size = 0;
  572. }
  573. pr_debug("get 32bit window: %d, base: 0x%x, size: 0x%x\n",
  574. window, *base, *size);
  575. return;
  576. }
  577. /*
  578. * mv64x60_set_32bit_window()
  579. *
  580. * Set the base address and size of a 32-bit window on the bridge.
  581. */
  582. void __init
  583. mv64x60_set_32bit_window(struct mv64x60_handle *bh, u32 window,
  584. u32 base, u32 size, u32 other_bits)
  585. {
  586. u32 val, base_reg, size_reg, base_bits, size_bits;
  587. u32 (*map_to_field)(u32 val, u32 num_bits);
  588. pr_debug("set 32bit window: %d, base: 0x%x, size: 0x%x, other: 0x%x\n",
  589. window, base, size, other_bits);
  590. base_reg = bh->ci->window_tab_32bit[window].base_reg;
  591. if (base_reg != 0) {
  592. size_reg = bh->ci->window_tab_32bit[window].size_reg;
  593. base_bits = bh->ci->window_tab_32bit[window].base_bits;
  594. size_bits = bh->ci->window_tab_32bit[window].size_bits;
  595. map_to_field = bh->ci->window_tab_32bit[window].map_to_field;
  596. val = map_to_field(base, base_bits) | other_bits;
  597. mv64x60_write(bh, base_reg, val);
  598. if (size_reg != 0) {
  599. val = bh->ci->translate_size(base, size, size_bits);
  600. val = map_to_field(val, size_bits);
  601. mv64x60_write(bh, size_reg, val);
  602. }
  603. (void)mv64x60_read(bh, base_reg); /* Flush FIFO */
  604. }
  605. return;
  606. }
  607. /*
  608. * mv64x60_get_64bit_window()
  609. *
  610. * Determine the base address and size of a 64-bit window on the bridge.
  611. */
  612. void __init
  613. mv64x60_get_64bit_window(struct mv64x60_handle *bh, u32 window,
  614. u32 *base_hi, u32 *base_lo, u32 *size)
  615. {
  616. u32 val, base_lo_reg, size_reg, base_lo_bits, size_bits;
  617. u32 (*get_from_field)(u32 val, u32 num_bits);
  618. base_lo_reg = bh->ci->window_tab_64bit[window].base_lo_reg;
  619. if (base_lo_reg != 0) {
  620. size_reg = bh->ci->window_tab_64bit[window].size_reg;
  621. base_lo_bits = bh->ci->window_tab_64bit[window].base_lo_bits;
  622. size_bits = bh->ci->window_tab_64bit[window].size_bits;
  623. get_from_field= bh->ci->window_tab_64bit[window].get_from_field;
  624. *base_hi = mv64x60_read(bh,
  625. bh->ci->window_tab_64bit[window].base_hi_reg);
  626. val = mv64x60_read(bh, base_lo_reg);
  627. *base_lo = get_from_field(val, base_lo_bits);
  628. if (size_reg != 0) {
  629. val = mv64x60_read(bh, size_reg);
  630. val = get_from_field(val, size_bits);
  631. *size = bh->ci->untranslate_size(*base_lo, val,
  632. size_bits);
  633. }
  634. else
  635. *size = 0;
  636. }
  637. else {
  638. *base_hi = 0;
  639. *base_lo = 0;
  640. *size = 0;
  641. }
  642. pr_debug("get 64bit window: %d, base hi: 0x%x, base lo: 0x%x, "
  643. "size: 0x%x\n", window, *base_hi, *base_lo, *size);
  644. return;
  645. }
  646. /*
  647. * mv64x60_set_64bit_window()
  648. *
  649. * Set the base address and size of a 64-bit window on the bridge.
  650. */
  651. void __init
  652. mv64x60_set_64bit_window(struct mv64x60_handle *bh, u32 window,
  653. u32 base_hi, u32 base_lo, u32 size, u32 other_bits)
  654. {
  655. u32 val, base_lo_reg, size_reg, base_lo_bits, size_bits;
  656. u32 (*map_to_field)(u32 val, u32 num_bits);
  657. pr_debug("set 64bit window: %d, base hi: 0x%x, base lo: 0x%x, "
  658. "size: 0x%x, other: 0x%x\n",
  659. window, base_hi, base_lo, size, other_bits);
  660. base_lo_reg = bh->ci->window_tab_64bit[window].base_lo_reg;
  661. if (base_lo_reg != 0) {
  662. size_reg = bh->ci->window_tab_64bit[window].size_reg;
  663. base_lo_bits = bh->ci->window_tab_64bit[window].base_lo_bits;
  664. size_bits = bh->ci->window_tab_64bit[window].size_bits;
  665. map_to_field = bh->ci->window_tab_64bit[window].map_to_field;
  666. mv64x60_write(bh, bh->ci->window_tab_64bit[window].base_hi_reg,
  667. base_hi);
  668. val = map_to_field(base_lo, base_lo_bits) | other_bits;
  669. mv64x60_write(bh, base_lo_reg, val);
  670. if (size_reg != 0) {
  671. val = bh->ci->translate_size(base_lo, size, size_bits);
  672. val = map_to_field(val, size_bits);
  673. mv64x60_write(bh, size_reg, val);
  674. }
  675. (void)mv64x60_read(bh, base_lo_reg); /* Flush FIFO */
  676. }
  677. return;
  678. }
  679. /*
  680. * mv64x60_mask()
  681. *
  682. * Take the high-order 'num_bits' of 'val' & mask off low bits.
  683. */
  684. u32 __init
  685. mv64x60_mask(u32 val, u32 num_bits)
  686. {
  687. return val & (0xffffffff << (32 - num_bits));
  688. }
  689. /*
  690. * mv64x60_shift_left()
  691. *
  692. * Take the low-order 'num_bits' of 'val', shift left to align at bit 31 (MSB).
  693. */
  694. u32 __init
  695. mv64x60_shift_left(u32 val, u32 num_bits)
  696. {
  697. return val << (32 - num_bits);
  698. }
  699. /*
  700. * mv64x60_shift_right()
  701. *
  702. * Take the high-order 'num_bits' of 'val', shift right to align at bit 0 (LSB).
  703. */
  704. u32 __init
  705. mv64x60_shift_right(u32 val, u32 num_bits)
  706. {
  707. return val >> (32 - num_bits);
  708. }
  709. /*
  710. *****************************************************************************
  711. *
  712. * Chip Identification Routines
  713. *
  714. *****************************************************************************
  715. */
  716. /*
  717. * mv64x60_get_type()
  718. *
  719. * Determine the type of bridge chip we have.
  720. */
  721. int __init
  722. mv64x60_get_type(struct mv64x60_handle *bh)
  723. {
  724. struct pci_controller hose;
  725. u16 val;
  726. u8 save_exclude;
  727. memset(&hose, 0, sizeof(hose));
  728. setup_indirect_pci_nomap(&hose, bh->v_base + MV64x60_PCI0_CONFIG_ADDR,
  729. bh->v_base + MV64x60_PCI0_CONFIG_DATA);
  730. save_exclude = mv64x60_pci_exclude_bridge;
  731. mv64x60_pci_exclude_bridge = 0;
  732. /* Sanity check of bridge's Vendor ID */
  733. early_read_config_word(&hose, 0, PCI_DEVFN(0, 0), PCI_VENDOR_ID, &val);
  734. if (val != PCI_VENDOR_ID_MARVELL) {
  735. mv64x60_pci_exclude_bridge = save_exclude;
  736. return -1;
  737. }
  738. /* Get the revision of the chip */
  739. early_read_config_word(&hose, 0, PCI_DEVFN(0, 0), PCI_CLASS_REVISION,
  740. &val);
  741. bh->rev = (u32)(val & 0xff);
  742. /* Figure out the type of Marvell bridge it is */
  743. early_read_config_word(&hose, 0, PCI_DEVFN(0, 0), PCI_DEVICE_ID, &val);
  744. mv64x60_pci_exclude_bridge = save_exclude;
  745. switch (val) {
  746. case PCI_DEVICE_ID_MARVELL_GT64260:
  747. switch (bh->rev) {
  748. case GT64260_REV_A:
  749. bh->type = MV64x60_TYPE_GT64260A;
  750. break;
  751. default:
  752. printk(KERN_WARNING "Unsupported GT64260 rev %04x\n",
  753. bh->rev);
  754. /* Assume its similar to a 'B' rev and fallthru */
  755. case GT64260_REV_B:
  756. bh->type = MV64x60_TYPE_GT64260B;
  757. break;
  758. }
  759. break;
  760. case PCI_DEVICE_ID_MARVELL_MV64360:
  761. /* Marvell won't tell me how to distinguish a 64361 & 64362 */
  762. bh->type = MV64x60_TYPE_MV64360;
  763. break;
  764. case PCI_DEVICE_ID_MARVELL_MV64460:
  765. bh->type = MV64x60_TYPE_MV64460;
  766. break;
  767. default:
  768. printk(KERN_ERR "Unknown Marvell bridge type %04x\n", val);
  769. return -1;
  770. }
  771. /* Hang onto bridge type & rev for PIC code */
  772. mv64x60_bridge_type = bh->type;
  773. mv64x60_bridge_rev = bh->rev;
  774. return 0;
  775. }
  776. /*
  777. * mv64x60_setup_for_chip()
  778. *
  779. * Set 'bh' to use the proper set of routine for the bridge chip that we have.
  780. */
  781. int __init
  782. mv64x60_setup_for_chip(struct mv64x60_handle *bh)
  783. {
  784. int rc = 0;
  785. /* Set up chip-specific info based on the chip/bridge type */
  786. switch(bh->type) {
  787. case MV64x60_TYPE_GT64260A:
  788. bh->ci = &gt64260a_ci;
  789. break;
  790. case MV64x60_TYPE_GT64260B:
  791. bh->ci = &gt64260b_ci;
  792. break;
  793. case MV64x60_TYPE_MV64360:
  794. bh->ci = &mv64360_ci;
  795. break;
  796. case MV64x60_TYPE_MV64460:
  797. bh->ci = &mv64460_ci;
  798. break;
  799. case MV64x60_TYPE_INVALID:
  800. default:
  801. if (ppc_md.progress)
  802. ppc_md.progress("mv64x60: Unsupported bridge", 0x0);
  803. printk(KERN_ERR "mv64x60: Unsupported bridge\n");
  804. rc = -1;
  805. }
  806. return rc;
  807. }
  808. /*
  809. * mv64x60_get_bridge_vbase()
  810. *
  811. * Return the virtual address of the bridge's registers.
  812. */
  813. void *
  814. mv64x60_get_bridge_vbase(void)
  815. {
  816. return mv64x60_bridge_vbase;
  817. }
  818. /*
  819. * mv64x60_get_bridge_type()
  820. *
  821. * Return the type of bridge on the platform.
  822. */
  823. u32
  824. mv64x60_get_bridge_type(void)
  825. {
  826. return mv64x60_bridge_type;
  827. }
  828. /*
  829. * mv64x60_get_bridge_rev()
  830. *
  831. * Return the revision of the bridge on the platform.
  832. */
  833. u32
  834. mv64x60_get_bridge_rev(void)
  835. {
  836. return mv64x60_bridge_rev;
  837. }
  838. /*
  839. *****************************************************************************
  840. *
  841. * System Memory Window Related Routines
  842. *
  843. *****************************************************************************
  844. */
  845. /*
  846. * mv64x60_get_mem_size()
  847. *
  848. * Calculate the amount of memory that the memory controller is set up for.
  849. * This should only be used by board-specific code if there is no other
  850. * way to determine the amount of memory in the system.
  851. */
  852. u32 __init
  853. mv64x60_get_mem_size(u32 bridge_base, u32 chip_type)
  854. {
  855. struct mv64x60_handle bh;
  856. u32 mem_windows[MV64x60_CPU2MEM_WINDOWS][2];
  857. u32 rc = 0;
  858. memset(&bh, 0, sizeof(bh));
  859. bh.type = chip_type;
  860. bh.v_base = (void *)bridge_base;
  861. if (!mv64x60_setup_for_chip(&bh)) {
  862. mv64x60_get_mem_windows(&bh, mem_windows);
  863. rc = mv64x60_calc_mem_size(&bh, mem_windows);
  864. }
  865. return rc;
  866. }
  867. /*
  868. * mv64x60_get_mem_windows()
  869. *
  870. * Get the values in the memory controller & return in the 'mem_windows' array.
  871. */
  872. void __init
  873. mv64x60_get_mem_windows(struct mv64x60_handle *bh,
  874. u32 mem_windows[MV64x60_CPU2MEM_WINDOWS][2])
  875. {
  876. u32 i, win;
  877. for (win=MV64x60_CPU2MEM_0_WIN,i=0;win<=MV64x60_CPU2MEM_3_WIN;win++,i++)
  878. if (bh->ci->is_enabled_32bit(bh, win))
  879. mv64x60_get_32bit_window(bh, win,
  880. &mem_windows[i][0], &mem_windows[i][1]);
  881. else {
  882. mem_windows[i][0] = 0;
  883. mem_windows[i][1] = 0;
  884. }
  885. return;
  886. }
  887. /*
  888. * mv64x60_calc_mem_size()
  889. *
  890. * Using the memory controller register values in 'mem_windows', determine
  891. * how much memory it is set up for.
  892. */
  893. u32 __init
  894. mv64x60_calc_mem_size(struct mv64x60_handle *bh,
  895. u32 mem_windows[MV64x60_CPU2MEM_WINDOWS][2])
  896. {
  897. u32 i, total = 0;
  898. for (i=0; i<MV64x60_CPU2MEM_WINDOWS; i++)
  899. total += mem_windows[i][1];
  900. return total;
  901. }
  902. /*
  903. *****************************************************************************
  904. *
  905. * CPU->System MEM, PCI Config Routines
  906. *
  907. *****************************************************************************
  908. */
  909. /*
  910. * mv64x60_config_cpu2mem_windows()
  911. *
  912. * Configure CPU->Memory windows on the bridge.
  913. */
  914. static u32 prot_tab[] __initdata = {
  915. MV64x60_CPU_PROT_0_WIN, MV64x60_CPU_PROT_1_WIN,
  916. MV64x60_CPU_PROT_2_WIN, MV64x60_CPU_PROT_3_WIN
  917. };
  918. static u32 cpu_snoop_tab[] __initdata = {
  919. MV64x60_CPU_SNOOP_0_WIN, MV64x60_CPU_SNOOP_1_WIN,
  920. MV64x60_CPU_SNOOP_2_WIN, MV64x60_CPU_SNOOP_3_WIN
  921. };
  922. void __init
  923. mv64x60_config_cpu2mem_windows(struct mv64x60_handle *bh,
  924. struct mv64x60_setup_info *si,
  925. u32 mem_windows[MV64x60_CPU2MEM_WINDOWS][2])
  926. {
  927. u32 i, win;
  928. /* Set CPU protection & snoop windows */
  929. for (win=MV64x60_CPU2MEM_0_WIN,i=0;win<=MV64x60_CPU2MEM_3_WIN;win++,i++)
  930. if (bh->ci->is_enabled_32bit(bh, win)) {
  931. mv64x60_set_32bit_window(bh, prot_tab[i],
  932. mem_windows[i][0], mem_windows[i][1],
  933. si->cpu_prot_options[i]);
  934. bh->ci->enable_window_32bit(bh, prot_tab[i]);
  935. if (bh->ci->window_tab_32bit[cpu_snoop_tab[i]].
  936. base_reg != 0) {
  937. mv64x60_set_32bit_window(bh, cpu_snoop_tab[i],
  938. mem_windows[i][0], mem_windows[i][1],
  939. si->cpu_snoop_options[i]);
  940. bh->ci->enable_window_32bit(bh,
  941. cpu_snoop_tab[i]);
  942. }
  943. }
  944. return;
  945. }
  946. /*
  947. * mv64x60_config_cpu2pci_windows()
  948. *
  949. * Configure the CPU->PCI windows for one of the PCI buses.
  950. */
  951. static u32 win_tab[2][4] __initdata = {
  952. { MV64x60_CPU2PCI0_IO_WIN, MV64x60_CPU2PCI0_MEM_0_WIN,
  953. MV64x60_CPU2PCI0_MEM_1_WIN, MV64x60_CPU2PCI0_MEM_2_WIN },
  954. { MV64x60_CPU2PCI1_IO_WIN, MV64x60_CPU2PCI1_MEM_0_WIN,
  955. MV64x60_CPU2PCI1_MEM_1_WIN, MV64x60_CPU2PCI1_MEM_2_WIN },
  956. };
  957. static u32 remap_tab[2][4] __initdata = {
  958. { MV64x60_CPU2PCI0_IO_REMAP_WIN, MV64x60_CPU2PCI0_MEM_0_REMAP_WIN,
  959. MV64x60_CPU2PCI0_MEM_1_REMAP_WIN, MV64x60_CPU2PCI0_MEM_2_REMAP_WIN },
  960. { MV64x60_CPU2PCI1_IO_REMAP_WIN, MV64x60_CPU2PCI1_MEM_0_REMAP_WIN,
  961. MV64x60_CPU2PCI1_MEM_1_REMAP_WIN, MV64x60_CPU2PCI1_MEM_2_REMAP_WIN }
  962. };
  963. void __init
  964. mv64x60_config_cpu2pci_windows(struct mv64x60_handle *bh,
  965. struct mv64x60_pci_info *pi, u32 bus)
  966. {
  967. int i;
  968. if (pi->pci_io.size > 0) {
  969. mv64x60_set_32bit_window(bh, win_tab[bus][0],
  970. pi->pci_io.cpu_base, pi->pci_io.size, pi->pci_io.swap);
  971. mv64x60_set_32bit_window(bh, remap_tab[bus][0],
  972. pi->pci_io.pci_base_lo, 0, 0);
  973. bh->ci->enable_window_32bit(bh, win_tab[bus][0]);
  974. }
  975. else /* Actually, the window should already be disabled */
  976. bh->ci->disable_window_32bit(bh, win_tab[bus][0]);
  977. for (i=0; i<3; i++)
  978. if (pi->pci_mem[i].size > 0) {
  979. mv64x60_set_32bit_window(bh, win_tab[bus][i+1],
  980. pi->pci_mem[i].cpu_base, pi->pci_mem[i].size,
  981. pi->pci_mem[i].swap);
  982. mv64x60_set_64bit_window(bh, remap_tab[bus][i+1],
  983. pi->pci_mem[i].pci_base_hi,
  984. pi->pci_mem[i].pci_base_lo, 0, 0);
  985. bh->ci->enable_window_32bit(bh, win_tab[bus][i+1]);
  986. }
  987. else /* Actually, the window should already be disabled */
  988. bh->ci->disable_window_32bit(bh, win_tab[bus][i+1]);
  989. return;
  990. }
  991. /*
  992. *****************************************************************************
  993. *
  994. * PCI->System MEM Config Routines
  995. *
  996. *****************************************************************************
  997. */
  998. /*
  999. * mv64x60_config_pci2mem_windows()
  1000. *
  1001. * Configure the PCI->Memory windows on the bridge.
  1002. */
  1003. static u32 pci_acc_tab[2][4] __initdata = {
  1004. { MV64x60_PCI02MEM_ACC_CNTL_0_WIN, MV64x60_PCI02MEM_ACC_CNTL_1_WIN,
  1005. MV64x60_PCI02MEM_ACC_CNTL_2_WIN, MV64x60_PCI02MEM_ACC_CNTL_3_WIN },
  1006. { MV64x60_PCI12MEM_ACC_CNTL_0_WIN, MV64x60_PCI12MEM_ACC_CNTL_1_WIN,
  1007. MV64x60_PCI12MEM_ACC_CNTL_2_WIN, MV64x60_PCI12MEM_ACC_CNTL_3_WIN }
  1008. };
  1009. static u32 pci_snoop_tab[2][4] __initdata = {
  1010. { MV64x60_PCI02MEM_SNOOP_0_WIN, MV64x60_PCI02MEM_SNOOP_1_WIN,
  1011. MV64x60_PCI02MEM_SNOOP_2_WIN, MV64x60_PCI02MEM_SNOOP_3_WIN },
  1012. { MV64x60_PCI12MEM_SNOOP_0_WIN, MV64x60_PCI12MEM_SNOOP_1_WIN,
  1013. MV64x60_PCI12MEM_SNOOP_2_WIN, MV64x60_PCI12MEM_SNOOP_3_WIN }
  1014. };
  1015. static u32 pci_size_tab[2][4] __initdata = {
  1016. { MV64x60_PCI0_MEM_0_SIZE, MV64x60_PCI0_MEM_1_SIZE,
  1017. MV64x60_PCI0_MEM_2_SIZE, MV64x60_PCI0_MEM_3_SIZE },
  1018. { MV64x60_PCI1_MEM_0_SIZE, MV64x60_PCI1_MEM_1_SIZE,
  1019. MV64x60_PCI1_MEM_2_SIZE, MV64x60_PCI1_MEM_3_SIZE }
  1020. };
  1021. void __init
  1022. mv64x60_config_pci2mem_windows(struct mv64x60_handle *bh,
  1023. struct pci_controller *hose, struct mv64x60_pci_info *pi,
  1024. u32 bus, u32 mem_windows[MV64x60_CPU2MEM_WINDOWS][2])
  1025. {
  1026. u32 i, win;
  1027. /*
  1028. * Set the access control, snoop, BAR size, and window base addresses.
  1029. * PCI->MEM windows base addresses will match exactly what the
  1030. * CPU->MEM windows are.
  1031. */
  1032. for (win=MV64x60_CPU2MEM_0_WIN,i=0;win<=MV64x60_CPU2MEM_3_WIN;win++,i++)
  1033. if (bh->ci->is_enabled_32bit(bh, win)) {
  1034. mv64x60_set_64bit_window(bh,
  1035. pci_acc_tab[bus][i], 0,
  1036. mem_windows[i][0], mem_windows[i][1],
  1037. pi->acc_cntl_options[i]);
  1038. bh->ci->enable_window_64bit(bh, pci_acc_tab[bus][i]);
  1039. if (bh->ci->window_tab_64bit[
  1040. pci_snoop_tab[bus][i]].base_lo_reg != 0) {
  1041. mv64x60_set_64bit_window(bh,
  1042. pci_snoop_tab[bus][i], 0,
  1043. mem_windows[i][0], mem_windows[i][1],
  1044. pi->snoop_options[i]);
  1045. bh->ci->enable_window_64bit(bh,
  1046. pci_snoop_tab[bus][i]);
  1047. }
  1048. bh->ci->set_pci2mem_window(hose, bus, i,
  1049. mem_windows[i][0]);
  1050. mv64x60_write(bh, pci_size_tab[bus][i],
  1051. mv64x60_mask(mem_windows[i][1] - 1, 20));
  1052. /* Enable the window */
  1053. mv64x60_clr_bits(bh, ((bus == 0) ?
  1054. MV64x60_PCI0_BAR_ENABLE :
  1055. MV64x60_PCI1_BAR_ENABLE), (1 << i));
  1056. }
  1057. return;
  1058. }
  1059. /*
  1060. *****************************************************************************
  1061. *
  1062. * Hose & Resource Alloc/Init Routines
  1063. *
  1064. *****************************************************************************
  1065. */
  1066. /*
  1067. * mv64x60_alloc_hoses()
  1068. *
  1069. * Allocate the PCI hose structures for the bridge's PCI buses.
  1070. */
  1071. void __init
  1072. mv64x60_alloc_hose(struct mv64x60_handle *bh, u32 cfg_addr, u32 cfg_data,
  1073. struct pci_controller **hose)
  1074. {
  1075. *hose = pcibios_alloc_controller();
  1076. setup_indirect_pci_nomap(*hose, bh->v_base + cfg_addr,
  1077. bh->v_base + cfg_data);
  1078. return;
  1079. }
  1080. /*
  1081. * mv64x60_config_resources()
  1082. *
  1083. * Calculate the offsets, etc. for the hose structures to reflect all of
  1084. * the address remapping that happens as you go from CPU->PCI and PCI->MEM.
  1085. */
  1086. void __init
  1087. mv64x60_config_resources(struct pci_controller *hose,
  1088. struct mv64x60_pci_info *pi, u32 io_base)
  1089. {
  1090. int i;
  1091. /* 2 hoses; 4 resources/hose; string <= 64 bytes */
  1092. static char s[2][4][64];
  1093. if (pi->pci_io.size != 0) {
  1094. sprintf(s[hose->index][0], "PCI hose %d I/O Space",
  1095. hose->index);
  1096. pci_init_resource(&hose->io_resource, io_base - isa_io_base,
  1097. io_base - isa_io_base + pi->pci_io.size - 1,
  1098. IORESOURCE_IO, s[hose->index][0]);
  1099. hose->io_space.start = pi->pci_io.pci_base_lo;
  1100. hose->io_space.end = pi->pci_io.pci_base_lo + pi->pci_io.size-1;
  1101. hose->io_base_phys = pi->pci_io.cpu_base;
  1102. hose->io_base_virt = (void *)isa_io_base;
  1103. }
  1104. for (i=0; i<3; i++)
  1105. if (pi->pci_mem[i].size != 0) {
  1106. sprintf(s[hose->index][i+1], "PCI hose %d MEM Space %d",
  1107. hose->index, i);
  1108. pci_init_resource(&hose->mem_resources[i],
  1109. pi->pci_mem[i].cpu_base,
  1110. pi->pci_mem[i].cpu_base + pi->pci_mem[i].size-1,
  1111. IORESOURCE_MEM, s[hose->index][i+1]);
  1112. }
  1113. hose->mem_space.end = pi->pci_mem[0].pci_base_lo +
  1114. pi->pci_mem[0].size - 1;
  1115. hose->pci_mem_offset = pi->pci_mem[0].cpu_base -
  1116. pi->pci_mem[0].pci_base_lo;
  1117. return;
  1118. }
  1119. /*
  1120. * mv64x60_config_pci_params()
  1121. *
  1122. * Configure a hose's PCI config space parameters.
  1123. */
  1124. void __init
  1125. mv64x60_config_pci_params(struct pci_controller *hose,
  1126. struct mv64x60_pci_info *pi)
  1127. {
  1128. u32 devfn;
  1129. u16 u16_val;
  1130. u8 save_exclude;
  1131. devfn = PCI_DEVFN(0,0);
  1132. save_exclude = mv64x60_pci_exclude_bridge;
  1133. mv64x60_pci_exclude_bridge = 0;
  1134. /* Set class code to indicate host bridge */
  1135. u16_val = PCI_CLASS_BRIDGE_HOST; /* 0x0600 (host bridge) */
  1136. early_write_config_word(hose, 0, devfn, PCI_CLASS_DEVICE, u16_val);
  1137. /* Enable bridge to be PCI master & respond to PCI MEM cycles */
  1138. early_read_config_word(hose, 0, devfn, PCI_COMMAND, &u16_val);
  1139. u16_val &= ~(PCI_COMMAND_IO | PCI_COMMAND_INVALIDATE |
  1140. PCI_COMMAND_PARITY | PCI_COMMAND_SERR | PCI_COMMAND_FAST_BACK);
  1141. u16_val |= pi->pci_cmd_bits | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  1142. early_write_config_word(hose, 0, devfn, PCI_COMMAND, u16_val);
  1143. /* Set latency timer, cache line size, clear BIST */
  1144. u16_val = (pi->latency_timer << 8) | (L1_CACHE_LINE_SIZE >> 2);
  1145. early_write_config_word(hose, 0, devfn, PCI_CACHE_LINE_SIZE, u16_val);
  1146. mv64x60_pci_exclude_bridge = save_exclude;
  1147. return;
  1148. }
  1149. /*
  1150. *****************************************************************************
  1151. *
  1152. * PCI Related Routine
  1153. *
  1154. *****************************************************************************
  1155. */
  1156. /*
  1157. * mv64x60_set_bus()
  1158. *
  1159. * Set the bus number for the hose directly under the bridge.
  1160. */
  1161. void __init
  1162. mv64x60_set_bus(struct mv64x60_handle *bh, u32 bus, u32 child_bus)
  1163. {
  1164. struct pci_controller *hose;
  1165. u32 pci_mode, p2p_cfg, pci_cfg_offset, val;
  1166. u8 save_exclude;
  1167. if (bus == 0) {
  1168. pci_mode = bh->pci_mode_a;
  1169. p2p_cfg = MV64x60_PCI0_P2P_CONFIG;
  1170. pci_cfg_offset = 0x64;
  1171. hose = bh->hose_a;
  1172. }
  1173. else {
  1174. pci_mode = bh->pci_mode_b;
  1175. p2p_cfg = MV64x60_PCI1_P2P_CONFIG;
  1176. pci_cfg_offset = 0xe4;
  1177. hose = bh->hose_b;
  1178. }
  1179. child_bus &= 0xff;
  1180. val = mv64x60_read(bh, p2p_cfg);
  1181. if (pci_mode == MV64x60_PCIMODE_CONVENTIONAL) {
  1182. val &= 0xe0000000; /* Force dev num to 0, turn off P2P bridge */
  1183. val |= (child_bus << 16) | 0xff;
  1184. mv64x60_write(bh, p2p_cfg, val);
  1185. (void)mv64x60_read(bh, p2p_cfg); /* Flush FIFO */
  1186. }
  1187. else { /* PCI-X */
  1188. /*
  1189. * Need to use the current bus/dev number (that's in the
  1190. * P2P CONFIG reg) to access the bridge's pci config space.
  1191. */
  1192. save_exclude = mv64x60_pci_exclude_bridge;
  1193. mv64x60_pci_exclude_bridge = 0;
  1194. early_write_config_dword(hose, (val & 0x00ff0000) >> 16,
  1195. PCI_DEVFN(((val & 0x1f000000) >> 24), 0),
  1196. pci_cfg_offset, child_bus << 8);
  1197. mv64x60_pci_exclude_bridge = save_exclude;
  1198. }
  1199. return;
  1200. }
  1201. /*
  1202. * mv64x60_pci_exclude_device()
  1203. *
  1204. * This routine is used to make the bridge not appear when the
  1205. * PCI subsystem is accessing PCI devices (in PCI config space).
  1206. */
  1207. int
  1208. mv64x60_pci_exclude_device(u8 bus, u8 devfn)
  1209. {
  1210. struct pci_controller *hose;
  1211. hose = pci_bus_to_hose(bus);
  1212. /* Skip slot 0 on both hoses */
  1213. if ((mv64x60_pci_exclude_bridge == 1) && (PCI_SLOT(devfn) == 0) &&
  1214. (hose->first_busno == bus))
  1215. return PCIBIOS_DEVICE_NOT_FOUND;
  1216. else
  1217. return PCIBIOS_SUCCESSFUL;
  1218. } /* mv64x60_pci_exclude_device() */
  1219. /*
  1220. *****************************************************************************
  1221. *
  1222. * Platform Device Routines
  1223. *
  1224. *****************************************************************************
  1225. */
  1226. /*
  1227. * mv64x60_pd_fixup()
  1228. *
  1229. * Need to add the base addr of where the bridge's regs are mapped in the
  1230. * physical addr space so drivers can ioremap() them.
  1231. */
  1232. void __init
  1233. mv64x60_pd_fixup(struct mv64x60_handle *bh, struct platform_device *pd_devs[],
  1234. u32 entries)
  1235. {
  1236. struct resource *r;
  1237. u32 i, j;
  1238. for (i=0; i<entries; i++) {
  1239. j = 0;
  1240. while ((r = platform_get_resource(pd_devs[i],IORESOURCE_MEM,j))
  1241. != NULL) {
  1242. r->start += bh->p_base;
  1243. r->end += bh->p_base;
  1244. j++;
  1245. }
  1246. }
  1247. return;
  1248. }
  1249. /*
  1250. * mv64x60_add_pds()
  1251. *
  1252. * Add the mv64x60 platform devices to the list of platform devices.
  1253. */
  1254. static int __init
  1255. mv64x60_add_pds(void)
  1256. {
  1257. return platform_add_devices(mv64x60_pd_devs,
  1258. ARRAY_SIZE(mv64x60_pd_devs));
  1259. }
  1260. arch_initcall(mv64x60_add_pds);
  1261. /*
  1262. *****************************************************************************
  1263. *
  1264. * GT64260-Specific Routines
  1265. *
  1266. *****************************************************************************
  1267. */
  1268. /*
  1269. * gt64260_translate_size()
  1270. *
  1271. * On the GT64260, the size register is really the "top" address of the window.
  1272. */
  1273. static u32 __init
  1274. gt64260_translate_size(u32 base, u32 size, u32 num_bits)
  1275. {
  1276. return base + mv64x60_mask(size - 1, num_bits);
  1277. }
  1278. /*
  1279. * gt64260_untranslate_size()
  1280. *
  1281. * Translate the top address of a window into a window size.
  1282. */
  1283. static u32 __init
  1284. gt64260_untranslate_size(u32 base, u32 size, u32 num_bits)
  1285. {
  1286. if (size >= base)
  1287. size = size - base + (1 << (32 - num_bits));
  1288. else
  1289. size = 0;
  1290. return size;
  1291. }
  1292. /*
  1293. * gt64260_set_pci2mem_window()
  1294. *
  1295. * The PCI->MEM window registers are actually in PCI config space so need
  1296. * to set them by setting the correct config space BARs.
  1297. */
  1298. static u32 gt64260_reg_addrs[2][4] __initdata = {
  1299. { 0x10, 0x14, 0x18, 0x1c }, { 0x90, 0x94, 0x98, 0x9c }
  1300. };
  1301. static void __init
  1302. gt64260_set_pci2mem_window(struct pci_controller *hose, u32 bus, u32 window,
  1303. u32 base)
  1304. {
  1305. u8 save_exclude;
  1306. pr_debug("set pci->mem window: %d, hose: %d, base: 0x%x\n", window,
  1307. hose->index, base);
  1308. save_exclude = mv64x60_pci_exclude_bridge;
  1309. mv64x60_pci_exclude_bridge = 0;
  1310. early_write_config_dword(hose, 0, PCI_DEVFN(0, 0),
  1311. gt64260_reg_addrs[bus][window], mv64x60_mask(base, 20) | 0x8);
  1312. mv64x60_pci_exclude_bridge = save_exclude;
  1313. return;
  1314. }
  1315. /*
  1316. * gt64260_set_pci2regs_window()
  1317. *
  1318. * Set where the bridge's registers appear in PCI MEM space.
  1319. */
  1320. static u32 gt64260_offset[2] __initdata = {0x20, 0xa0};
  1321. static void __init
  1322. gt64260_set_pci2regs_window(struct mv64x60_handle *bh,
  1323. struct pci_controller *hose, u32 bus, u32 base)
  1324. {
  1325. u8 save_exclude;
  1326. pr_debug("set pci->internal regs hose: %d, base: 0x%x\n", hose->index,
  1327. base);
  1328. save_exclude = mv64x60_pci_exclude_bridge;
  1329. mv64x60_pci_exclude_bridge = 0;
  1330. early_write_config_dword(hose, 0, PCI_DEVFN(0,0), gt64260_offset[bus],
  1331. (base << 16));
  1332. mv64x60_pci_exclude_bridge = save_exclude;
  1333. return;
  1334. }
  1335. /*
  1336. * gt64260_is_enabled_32bit()
  1337. *
  1338. * On a GT64260, a window is enabled iff its top address is >= to its base
  1339. * address.
  1340. */
  1341. static u32 __init
  1342. gt64260_is_enabled_32bit(struct mv64x60_handle *bh, u32 window)
  1343. {
  1344. u32 rc = 0;
  1345. if ((gt64260_32bit_windows[window].base_reg != 0) &&
  1346. (gt64260_32bit_windows[window].size_reg != 0) &&
  1347. ((mv64x60_read(bh, gt64260_32bit_windows[window].size_reg) &
  1348. ((1 << gt64260_32bit_windows[window].size_bits) - 1)) >=
  1349. (mv64x60_read(bh, gt64260_32bit_windows[window].base_reg) &
  1350. ((1 << gt64260_32bit_windows[window].base_bits) - 1))))
  1351. rc = 1;
  1352. return rc;
  1353. }
  1354. /*
  1355. * gt64260_enable_window_32bit()
  1356. *
  1357. * On the GT64260, a window is enabled iff the top address is >= to the base
  1358. * address of the window. Since the window has already been configured by
  1359. * the time this routine is called, we have nothing to do here.
  1360. */
  1361. static void __init
  1362. gt64260_enable_window_32bit(struct mv64x60_handle *bh, u32 window)
  1363. {
  1364. pr_debug("enable 32bit window: %d\n", window);
  1365. return;
  1366. }
  1367. /*
  1368. * gt64260_disable_window_32bit()
  1369. *
  1370. * On a GT64260, you disable a window by setting its top address to be less
  1371. * than its base address.
  1372. */
  1373. static void __init
  1374. gt64260_disable_window_32bit(struct mv64x60_handle *bh, u32 window)
  1375. {
  1376. pr_debug("disable 32bit window: %d, base_reg: 0x%x, size_reg: 0x%x\n",
  1377. window, gt64260_32bit_windows[window].base_reg,
  1378. gt64260_32bit_windows[window].size_reg);
  1379. if ((gt64260_32bit_windows[window].base_reg != 0) &&
  1380. (gt64260_32bit_windows[window].size_reg != 0)) {
  1381. /* To disable, make bottom reg higher than top reg */
  1382. mv64x60_write(bh, gt64260_32bit_windows[window].base_reg,0xfff);
  1383. mv64x60_write(bh, gt64260_32bit_windows[window].size_reg, 0);
  1384. }
  1385. return;
  1386. }
  1387. /*
  1388. * gt64260_enable_window_64bit()
  1389. *
  1390. * On the GT64260, a window is enabled iff the top address is >= to the base
  1391. * address of the window. Since the window has already been configured by
  1392. * the time this routine is called, we have nothing to do here.
  1393. */
  1394. static void __init
  1395. gt64260_enable_window_64bit(struct mv64x60_handle *bh, u32 window)
  1396. {
  1397. pr_debug("enable 64bit window: %d\n", window);
  1398. return; /* Enabled when window configured (i.e., when top >= base) */
  1399. }
  1400. /*
  1401. * gt64260_disable_window_64bit()
  1402. *
  1403. * On a GT64260, you disable a window by setting its top address to be less
  1404. * than its base address.
  1405. */
  1406. static void __init
  1407. gt64260_disable_window_64bit(struct mv64x60_handle *bh, u32 window)
  1408. {
  1409. pr_debug("disable 64bit window: %d, base_reg: 0x%x, size_reg: 0x%x\n",
  1410. window, gt64260_64bit_windows[window].base_lo_reg,
  1411. gt64260_64bit_windows[window].size_reg);
  1412. if ((gt64260_64bit_windows[window].base_lo_reg != 0) &&
  1413. (gt64260_64bit_windows[window].size_reg != 0)) {
  1414. /* To disable, make bottom reg higher than top reg */
  1415. mv64x60_write(bh, gt64260_64bit_windows[window].base_lo_reg,
  1416. 0xfff);
  1417. mv64x60_write(bh, gt64260_64bit_windows[window].base_hi_reg, 0);
  1418. mv64x60_write(bh, gt64260_64bit_windows[window].size_reg, 0);
  1419. }
  1420. return;
  1421. }
  1422. /*
  1423. * gt64260_disable_all_windows()
  1424. *
  1425. * The GT64260 has several windows that aren't represented in the table of
  1426. * windows at the top of this file. This routine turns all of them off
  1427. * except for the memory controller windows, of course.
  1428. */
  1429. static void __init
  1430. gt64260_disable_all_windows(struct mv64x60_handle *bh,
  1431. struct mv64x60_setup_info *si)
  1432. {
  1433. u32 i, preserve;
  1434. /* Disable 32bit windows (don't disable cpu->mem windows) */
  1435. for (i=MV64x60_CPU2DEV_0_WIN; i<MV64x60_32BIT_WIN_COUNT; i++) {
  1436. if (i < 32)
  1437. preserve = si->window_preserve_mask_32_lo & (1 << i);
  1438. else
  1439. preserve = si->window_preserve_mask_32_hi & (1<<(i-32));
  1440. if (!preserve)
  1441. gt64260_disable_window_32bit(bh, i);
  1442. }
  1443. /* Disable 64bit windows */
  1444. for (i=0; i<MV64x60_64BIT_WIN_COUNT; i++)
  1445. if (!(si->window_preserve_mask_64 & (1<<i)))
  1446. gt64260_disable_window_64bit(bh, i);
  1447. /* Turn off cpu protection windows not in gt64260_32bit_windows[] */
  1448. mv64x60_write(bh, GT64260_CPU_PROT_BASE_4, 0xfff);
  1449. mv64x60_write(bh, GT64260_CPU_PROT_SIZE_4, 0);
  1450. mv64x60_write(bh, GT64260_CPU_PROT_BASE_5, 0xfff);
  1451. mv64x60_write(bh, GT64260_CPU_PROT_SIZE_5, 0);
  1452. mv64x60_write(bh, GT64260_CPU_PROT_BASE_6, 0xfff);
  1453. mv64x60_write(bh, GT64260_CPU_PROT_SIZE_6, 0);
  1454. mv64x60_write(bh, GT64260_CPU_PROT_BASE_7, 0xfff);
  1455. mv64x60_write(bh, GT64260_CPU_PROT_SIZE_7, 0);
  1456. /* Turn off PCI->MEM access cntl wins not in gt64260_64bit_windows[] */
  1457. mv64x60_write(bh, MV64x60_PCI0_ACC_CNTL_4_BASE_LO, 0xfff);
  1458. mv64x60_write(bh, MV64x60_PCI0_ACC_CNTL_4_BASE_HI, 0);
  1459. mv64x60_write(bh, MV64x60_PCI0_ACC_CNTL_4_SIZE, 0);
  1460. mv64x60_write(bh, MV64x60_PCI0_ACC_CNTL_5_BASE_LO, 0xfff);
  1461. mv64x60_write(bh, MV64x60_PCI0_ACC_CNTL_5_BASE_HI, 0);
  1462. mv64x60_write(bh, MV64x60_PCI0_ACC_CNTL_5_SIZE, 0);
  1463. mv64x60_write(bh, GT64260_PCI0_ACC_CNTL_6_BASE_LO, 0xfff);
  1464. mv64x60_write(bh, GT64260_PCI0_ACC_CNTL_6_BASE_HI, 0);
  1465. mv64x60_write(bh, GT64260_PCI0_ACC_CNTL_6_SIZE, 0);
  1466. mv64x60_write(bh, GT64260_PCI0_ACC_CNTL_7_BASE_LO, 0xfff);
  1467. mv64x60_write(bh, GT64260_PCI0_ACC_CNTL_7_BASE_HI, 0);
  1468. mv64x60_write(bh, GT64260_PCI0_ACC_CNTL_7_SIZE, 0);
  1469. mv64x60_write(bh, MV64x60_PCI1_ACC_CNTL_4_BASE_LO, 0xfff);
  1470. mv64x60_write(bh, MV64x60_PCI1_ACC_CNTL_4_BASE_HI, 0);
  1471. mv64x60_write(bh, MV64x60_PCI1_ACC_CNTL_4_SIZE, 0);
  1472. mv64x60_write(bh, MV64x60_PCI1_ACC_CNTL_5_BASE_LO, 0xfff);
  1473. mv64x60_write(bh, MV64x60_PCI1_ACC_CNTL_5_BASE_HI, 0);
  1474. mv64x60_write(bh, MV64x60_PCI1_ACC_CNTL_5_SIZE, 0);
  1475. mv64x60_write(bh, GT64260_PCI1_ACC_CNTL_6_BASE_LO, 0xfff);
  1476. mv64x60_write(bh, GT64260_PCI1_ACC_CNTL_6_BASE_HI, 0);
  1477. mv64x60_write(bh, GT64260_PCI1_ACC_CNTL_6_SIZE, 0);
  1478. mv64x60_write(bh, GT64260_PCI1_ACC_CNTL_7_BASE_LO, 0xfff);
  1479. mv64x60_write(bh, GT64260_PCI1_ACC_CNTL_7_BASE_HI, 0);
  1480. mv64x60_write(bh, GT64260_PCI1_ACC_CNTL_7_SIZE, 0);
  1481. /* Disable all PCI-><whatever> windows */
  1482. mv64x60_set_bits(bh, MV64x60_PCI0_BAR_ENABLE, 0x07fffdff);
  1483. mv64x60_set_bits(bh, MV64x60_PCI1_BAR_ENABLE, 0x07fffdff);
  1484. /*
  1485. * Some firmwares enable a bunch of intr sources
  1486. * for the PCI INT output pins.
  1487. */
  1488. mv64x60_write(bh, GT64260_IC_CPU_INTR_MASK_LO, 0);
  1489. mv64x60_write(bh, GT64260_IC_CPU_INTR_MASK_HI, 0);
  1490. mv64x60_write(bh, GT64260_IC_PCI0_INTR_MASK_LO, 0);
  1491. mv64x60_write(bh, GT64260_IC_PCI0_INTR_MASK_HI, 0);
  1492. mv64x60_write(bh, GT64260_IC_PCI1_INTR_MASK_LO, 0);
  1493. mv64x60_write(bh, GT64260_IC_PCI1_INTR_MASK_HI, 0);
  1494. mv64x60_write(bh, GT64260_IC_CPU_INT_0_MASK, 0);
  1495. mv64x60_write(bh, GT64260_IC_CPU_INT_1_MASK, 0);
  1496. mv64x60_write(bh, GT64260_IC_CPU_INT_2_MASK, 0);
  1497. mv64x60_write(bh, GT64260_IC_CPU_INT_3_MASK, 0);
  1498. return;
  1499. }
  1500. /*
  1501. * gt64260a_chip_specific_init()
  1502. *
  1503. * Implement errata work arounds for the GT64260A.
  1504. */
  1505. static void __init
  1506. gt64260a_chip_specific_init(struct mv64x60_handle *bh,
  1507. struct mv64x60_setup_info *si)
  1508. {
  1509. #ifdef CONFIG_SERIAL_MPSC
  1510. struct resource *r;
  1511. #endif
  1512. #if !defined(CONFIG_NOT_COHERENT_CACHE)
  1513. u32 val;
  1514. u8 save_exclude;
  1515. #endif
  1516. if (si->pci_0.enable_bus)
  1517. mv64x60_set_bits(bh, MV64x60_PCI0_CMD,
  1518. ((1<<4) | (1<<5) | (1<<9) | (1<<13)));
  1519. if (si->pci_1.enable_bus)
  1520. mv64x60_set_bits(bh, MV64x60_PCI1_CMD,
  1521. ((1<<4) | (1<<5) | (1<<9) | (1<<13)));
  1522. /*
  1523. * Dave Wilhardt found that bit 4 in the PCI Command registers must
  1524. * be set if you are using cache coherency.
  1525. */
  1526. #if !defined(CONFIG_NOT_COHERENT_CACHE)
  1527. /* Res #MEM-4 -- cpu read buffer to buffer 1 */
  1528. if ((mv64x60_read(bh, MV64x60_CPU_MODE) & 0xf0) == 0x40)
  1529. mv64x60_set_bits(bh, GT64260_SDRAM_CONFIG, (1<<26));
  1530. save_exclude = mv64x60_pci_exclude_bridge;
  1531. mv64x60_pci_exclude_bridge = 0;
  1532. if (si->pci_0.enable_bus) {
  1533. early_read_config_dword(bh->hose_a, 0, PCI_DEVFN(0,0),
  1534. PCI_COMMAND, &val);
  1535. val |= PCI_COMMAND_INVALIDATE;
  1536. early_write_config_dword(bh->hose_a, 0, PCI_DEVFN(0,0),
  1537. PCI_COMMAND, val);
  1538. }
  1539. if (si->pci_1.enable_bus) {
  1540. early_read_config_dword(bh->hose_b, 0, PCI_DEVFN(0,0),
  1541. PCI_COMMAND, &val);
  1542. val |= PCI_COMMAND_INVALIDATE;
  1543. early_write_config_dword(bh->hose_b, 0, PCI_DEVFN(0,0),
  1544. PCI_COMMAND, val);
  1545. }
  1546. mv64x60_pci_exclude_bridge = save_exclude;
  1547. #endif
  1548. /* Disable buffer/descriptor snooping */
  1549. mv64x60_clr_bits(bh, 0xf280, (1<< 6) | (1<<14) | (1<<22) | (1<<30));
  1550. mv64x60_clr_bits(bh, 0xf2c0, (1<< 6) | (1<<14) | (1<<22) | (1<<30));
  1551. #ifdef CONFIG_SERIAL_MPSC
  1552. mv64x60_mpsc0_pdata.mirror_regs = 1;
  1553. mv64x60_mpsc0_pdata.cache_mgmt = 1;
  1554. mv64x60_mpsc1_pdata.mirror_regs = 1;
  1555. mv64x60_mpsc1_pdata.cache_mgmt = 1;
  1556. if ((r = platform_get_resource(&mpsc1_device, IORESOURCE_IRQ, 0))
  1557. != NULL) {
  1558. r->start = MV64x60_IRQ_SDMA_0;
  1559. r->end = MV64x60_IRQ_SDMA_0;
  1560. }
  1561. #endif
  1562. return;
  1563. }
  1564. /*
  1565. * gt64260b_chip_specific_init()
  1566. *
  1567. * Implement errata work arounds for the GT64260B.
  1568. */
  1569. static void __init
  1570. gt64260b_chip_specific_init(struct mv64x60_handle *bh,
  1571. struct mv64x60_setup_info *si)
  1572. {
  1573. #ifdef CONFIG_SERIAL_MPSC
  1574. struct resource *r;
  1575. #endif
  1576. #if !defined(CONFIG_NOT_COHERENT_CACHE)
  1577. u32 val;
  1578. u8 save_exclude;
  1579. #endif
  1580. if (si->pci_0.enable_bus)
  1581. mv64x60_set_bits(bh, MV64x60_PCI0_CMD,
  1582. ((1<<4) | (1<<5) | (1<<9) | (1<<13)));
  1583. if (si->pci_1.enable_bus)
  1584. mv64x60_set_bits(bh, MV64x60_PCI1_CMD,
  1585. ((1<<4) | (1<<5) | (1<<9) | (1<<13)));
  1586. /*
  1587. * Dave Wilhardt found that bit 4 in the PCI Command registers must
  1588. * be set if you are using cache coherency.
  1589. */
  1590. #if !defined(CONFIG_NOT_COHERENT_CACHE)
  1591. mv64x60_set_bits(bh, GT64260_CPU_WB_PRIORITY_BUFFER_DEPTH, 0xf);
  1592. /* Res #MEM-4 -- cpu read buffer to buffer 1 */
  1593. if ((mv64x60_read(bh, MV64x60_CPU_MODE) & 0xf0) == 0x40)
  1594. mv64x60_set_bits(bh, GT64260_SDRAM_CONFIG, (1<<26));
  1595. save_exclude = mv64x60_pci_exclude_bridge;
  1596. mv64x60_pci_exclude_bridge = 0;
  1597. if (si->pci_0.enable_bus) {
  1598. early_read_config_dword(bh->hose_a, 0, PCI_DEVFN(0,0),
  1599. PCI_COMMAND, &val);
  1600. val |= PCI_COMMAND_INVALIDATE;
  1601. early_write_config_dword(bh->hose_a, 0, PCI_DEVFN(0,0),
  1602. PCI_COMMAND, val);
  1603. }
  1604. if (si->pci_1.enable_bus) {
  1605. early_read_config_dword(bh->hose_b, 0, PCI_DEVFN(0,0),
  1606. PCI_COMMAND, &val);
  1607. val |= PCI_COMMAND_INVALIDATE;
  1608. early_write_config_dword(bh->hose_b, 0, PCI_DEVFN(0,0),
  1609. PCI_COMMAND, val);
  1610. }
  1611. mv64x60_pci_exclude_bridge = save_exclude;
  1612. #endif
  1613. /* Disable buffer/descriptor snooping */
  1614. mv64x60_clr_bits(bh, 0xf280, (1<< 6) | (1<<14) | (1<<22) | (1<<30));
  1615. mv64x60_clr_bits(bh, 0xf2c0, (1<< 6) | (1<<14) | (1<<22) | (1<<30));
  1616. #ifdef CONFIG_SERIAL_MPSC
  1617. /*
  1618. * The 64260B is not supposed to have the bug where the MPSC & ENET
  1619. * can't access cache coherent regions. However, testing has shown
  1620. * that the MPSC, at least, still has this bug.
  1621. */
  1622. mv64x60_mpsc0_pdata.cache_mgmt = 1;
  1623. mv64x60_mpsc1_pdata.cache_mgmt = 1;
  1624. if ((r = platform_get_resource(&mpsc1_device, IORESOURCE_IRQ, 0))
  1625. != NULL) {
  1626. r->start = MV64x60_IRQ_SDMA_0;
  1627. r->end = MV64x60_IRQ_SDMA_0;
  1628. }
  1629. #endif
  1630. return;
  1631. }
  1632. /*
  1633. *****************************************************************************
  1634. *
  1635. * MV64360-Specific Routines
  1636. *
  1637. *****************************************************************************
  1638. */
  1639. /*
  1640. * mv64360_translate_size()
  1641. *
  1642. * On the MV64360, the size register is set similar to the size you get
  1643. * from a pci config space BAR register. That is, programmed from LSB to MSB
  1644. * as a sequence of 1's followed by a sequence of 0's. IOW, "size -1" with the
  1645. * assumption that the size is a power of 2.
  1646. */
  1647. static u32 __init
  1648. mv64360_translate_size(u32 base_addr, u32 size, u32 num_bits)
  1649. {
  1650. return mv64x60_mask(size - 1, num_bits);
  1651. }
  1652. /*
  1653. * mv64360_untranslate_size()
  1654. *
  1655. * Translate the size register value of a window into a window size.
  1656. */
  1657. static u32 __init
  1658. mv64360_untranslate_size(u32 base_addr, u32 size, u32 num_bits)
  1659. {
  1660. if (size > 0) {
  1661. size >>= (32 - num_bits);
  1662. size++;
  1663. size <<= (32 - num_bits);
  1664. }
  1665. return size;
  1666. }
  1667. /*
  1668. * mv64360_set_pci2mem_window()
  1669. *
  1670. * The PCI->MEM window registers are actually in PCI config space so need
  1671. * to set them by setting the correct config space BARs.
  1672. */
  1673. struct {
  1674. u32 fcn;
  1675. u32 base_hi_bar;
  1676. u32 base_lo_bar;
  1677. } static mv64360_reg_addrs[2][4] __initdata = {
  1678. {{ 0, 0x14, 0x10 }, { 0, 0x1c, 0x18 },
  1679. { 1, 0x14, 0x10 }, { 1, 0x1c, 0x18 }},
  1680. {{ 0, 0x94, 0x90 }, { 0, 0x9c, 0x98 },
  1681. { 1, 0x94, 0x90 }, { 1, 0x9c, 0x98 }}
  1682. };
  1683. static void __init
  1684. mv64360_set_pci2mem_window(struct pci_controller *hose, u32 bus, u32 window,
  1685. u32 base)
  1686. {
  1687. u8 save_exclude;
  1688. pr_debug("set pci->mem window: %d, hose: %d, base: 0x%x\n", window,
  1689. hose->index, base);
  1690. save_exclude = mv64x60_pci_exclude_bridge;
  1691. mv64x60_pci_exclude_bridge = 0;
  1692. early_write_config_dword(hose, 0,
  1693. PCI_DEVFN(0, mv64360_reg_addrs[bus][window].fcn),
  1694. mv64360_reg_addrs[bus][window].base_hi_bar, 0);
  1695. early_write_config_dword(hose, 0,
  1696. PCI_DEVFN(0, mv64360_reg_addrs[bus][window].fcn),
  1697. mv64360_reg_addrs[bus][window].base_lo_bar,
  1698. mv64x60_mask(base,20) | 0xc);
  1699. mv64x60_pci_exclude_bridge = save_exclude;
  1700. return;
  1701. }
  1702. /*
  1703. * mv64360_set_pci2regs_window()
  1704. *
  1705. * Set where the bridge's registers appear in PCI MEM space.
  1706. */
  1707. static u32 mv64360_offset[2][2] __initdata = {{0x20, 0x24}, {0xa0, 0xa4}};
  1708. static void __init
  1709. mv64360_set_pci2regs_window(struct mv64x60_handle *bh,
  1710. struct pci_controller *hose, u32 bus, u32 base)
  1711. {
  1712. u8 save_exclude;
  1713. pr_debug("set pci->internal regs hose: %d, base: 0x%x\n", hose->index,
  1714. base);
  1715. save_exclude = mv64x60_pci_exclude_bridge;
  1716. mv64x60_pci_exclude_bridge = 0;
  1717. early_write_config_dword(hose, 0, PCI_DEVFN(0,0),
  1718. mv64360_offset[bus][0], (base << 16));
  1719. early_write_config_dword(hose, 0, PCI_DEVFN(0,0),
  1720. mv64360_offset[bus][1], 0);
  1721. mv64x60_pci_exclude_bridge = save_exclude;
  1722. return;
  1723. }
  1724. /*
  1725. * mv64360_is_enabled_32bit()
  1726. *
  1727. * On a MV64360, a window is enabled by either clearing a bit in the
  1728. * CPU BAR Enable reg or setting a bit in the window's base reg.
  1729. * Note that this doesn't work for windows on the PCI slave side but we don't
  1730. * check those so its okay.
  1731. */
  1732. static u32 __init
  1733. mv64360_is_enabled_32bit(struct mv64x60_handle *bh, u32 window)
  1734. {
  1735. u32 extra, rc = 0;
  1736. if (((mv64360_32bit_windows[window].base_reg != 0) &&
  1737. (mv64360_32bit_windows[window].size_reg != 0)) ||
  1738. (window == MV64x60_CPU2SRAM_WIN)) {
  1739. extra = mv64360_32bit_windows[window].extra;
  1740. switch (extra & MV64x60_EXTRA_MASK) {
  1741. case MV64x60_EXTRA_CPUWIN_ENAB:
  1742. rc = (mv64x60_read(bh, MV64360_CPU_BAR_ENABLE) &
  1743. (1 << (extra & 0x1f))) == 0;
  1744. break;
  1745. case MV64x60_EXTRA_CPUPROT_ENAB:
  1746. rc = (mv64x60_read(bh,
  1747. mv64360_32bit_windows[window].base_reg) &
  1748. (1 << (extra & 0x1f))) != 0;
  1749. break;
  1750. case MV64x60_EXTRA_ENET_ENAB:
  1751. rc = (mv64x60_read(bh, MV64360_ENET2MEM_BAR_ENABLE) &
  1752. (1 << (extra & 0x7))) == 0;
  1753. break;
  1754. case MV64x60_EXTRA_MPSC_ENAB:
  1755. rc = (mv64x60_read(bh, MV64360_MPSC2MEM_BAR_ENABLE) &
  1756. (1 << (extra & 0x3))) == 0;
  1757. break;
  1758. case MV64x60_EXTRA_IDMA_ENAB:
  1759. rc = (mv64x60_read(bh, MV64360_IDMA2MEM_BAR_ENABLE) &
  1760. (1 << (extra & 0x7))) == 0;
  1761. break;
  1762. default:
  1763. printk(KERN_ERR "mv64360_is_enabled: %s\n",
  1764. "32bit table corrupted");
  1765. }
  1766. }
  1767. return rc;
  1768. }
  1769. /*
  1770. * mv64360_enable_window_32bit()
  1771. *
  1772. * On a MV64360, a window is enabled by either clearing a bit in the
  1773. * CPU BAR Enable reg or setting a bit in the window's base reg.
  1774. */
  1775. static void __init
  1776. mv64360_enable_window_32bit(struct mv64x60_handle *bh, u32 window)
  1777. {
  1778. u32 extra;
  1779. pr_debug("enable 32bit window: %d\n", window);
  1780. if (((mv64360_32bit_windows[window].base_reg != 0) &&
  1781. (mv64360_32bit_windows[window].size_reg != 0)) ||
  1782. (window == MV64x60_CPU2SRAM_WIN)) {
  1783. extra = mv64360_32bit_windows[window].extra;
  1784. switch (extra & MV64x60_EXTRA_MASK) {
  1785. case MV64x60_EXTRA_CPUWIN_ENAB:
  1786. mv64x60_clr_bits(bh, MV64360_CPU_BAR_ENABLE,
  1787. (1 << (extra & 0x1f)));
  1788. break;
  1789. case MV64x60_EXTRA_CPUPROT_ENAB:
  1790. mv64x60_set_bits(bh,
  1791. mv64360_32bit_windows[window].base_reg,
  1792. (1 << (extra & 0x1f)));
  1793. break;
  1794. case MV64x60_EXTRA_ENET_ENAB:
  1795. mv64x60_clr_bits(bh, MV64360_ENET2MEM_BAR_ENABLE,
  1796. (1 << (extra & 0x7)));
  1797. break;
  1798. case MV64x60_EXTRA_MPSC_ENAB:
  1799. mv64x60_clr_bits(bh, MV64360_MPSC2MEM_BAR_ENABLE,
  1800. (1 << (extra & 0x3)));
  1801. break;
  1802. case MV64x60_EXTRA_IDMA_ENAB:
  1803. mv64x60_clr_bits(bh, MV64360_IDMA2MEM_BAR_ENABLE,
  1804. (1 << (extra & 0x7)));
  1805. break;
  1806. default:
  1807. printk(KERN_ERR "mv64360_enable: %s\n",
  1808. "32bit table corrupted");
  1809. }
  1810. }
  1811. return;
  1812. }
  1813. /*
  1814. * mv64360_disable_window_32bit()
  1815. *
  1816. * On a MV64360, a window is disabled by either setting a bit in the
  1817. * CPU BAR Enable reg or clearing a bit in the window's base reg.
  1818. */
  1819. static void __init
  1820. mv64360_disable_window_32bit(struct mv64x60_handle *bh, u32 window)
  1821. {
  1822. u32 extra;
  1823. pr_debug("disable 32bit window: %d, base_reg: 0x%x, size_reg: 0x%x\n",
  1824. window, mv64360_32bit_windows[window].base_reg,
  1825. mv64360_32bit_windows[window].size_reg);
  1826. if (((mv64360_32bit_windows[window].base_reg != 0) &&
  1827. (mv64360_32bit_windows[window].size_reg != 0)) ||
  1828. (window == MV64x60_CPU2SRAM_WIN)) {
  1829. extra = mv64360_32bit_windows[window].extra;
  1830. switch (extra & MV64x60_EXTRA_MASK) {
  1831. case MV64x60_EXTRA_CPUWIN_ENAB:
  1832. mv64x60_set_bits(bh, MV64360_CPU_BAR_ENABLE,
  1833. (1 << (extra & 0x1f)));
  1834. break;
  1835. case MV64x60_EXTRA_CPUPROT_ENAB:
  1836. mv64x60_clr_bits(bh,
  1837. mv64360_32bit_windows[window].base_reg,
  1838. (1 << (extra & 0x1f)));
  1839. break;
  1840. case MV64x60_EXTRA_ENET_ENAB:
  1841. mv64x60_set_bits(bh, MV64360_ENET2MEM_BAR_ENABLE,
  1842. (1 << (extra & 0x7)));
  1843. break;
  1844. case MV64x60_EXTRA_MPSC_ENAB:
  1845. mv64x60_set_bits(bh, MV64360_MPSC2MEM_BAR_ENABLE,
  1846. (1 << (extra & 0x3)));
  1847. break;
  1848. case MV64x60_EXTRA_IDMA_ENAB:
  1849. mv64x60_set_bits(bh, MV64360_IDMA2MEM_BAR_ENABLE,
  1850. (1 << (extra & 0x7)));
  1851. break;
  1852. default:
  1853. printk(KERN_ERR "mv64360_disable: %s\n",
  1854. "32bit table corrupted");
  1855. }
  1856. }
  1857. return;
  1858. }
  1859. /*
  1860. * mv64360_enable_window_64bit()
  1861. *
  1862. * On the MV64360, a 64-bit window is enabled by setting a bit in the window's
  1863. * base reg.
  1864. */
  1865. static void __init
  1866. mv64360_enable_window_64bit(struct mv64x60_handle *bh, u32 window)
  1867. {
  1868. pr_debug("enable 64bit window: %d\n", window);
  1869. if ((mv64360_64bit_windows[window].base_lo_reg!= 0) &&
  1870. (mv64360_64bit_windows[window].size_reg != 0)) {
  1871. if ((mv64360_64bit_windows[window].extra & MV64x60_EXTRA_MASK)
  1872. == MV64x60_EXTRA_PCIACC_ENAB)
  1873. mv64x60_set_bits(bh,
  1874. mv64360_64bit_windows[window].base_lo_reg,
  1875. (1 << (mv64360_64bit_windows[window].extra &
  1876. 0x1f)));
  1877. else
  1878. printk(KERN_ERR "mv64360_enable: %s\n",
  1879. "64bit table corrupted");
  1880. }
  1881. return;
  1882. }
  1883. /*
  1884. * mv64360_disable_window_64bit()
  1885. *
  1886. * On a MV64360, a 64-bit window is disabled by clearing a bit in the window's
  1887. * base reg.
  1888. */
  1889. static void __init
  1890. mv64360_disable_window_64bit(struct mv64x60_handle *bh, u32 window)
  1891. {
  1892. pr_debug("disable 64bit window: %d, base_reg: 0x%x, size_reg: 0x%x\n",
  1893. window, mv64360_64bit_windows[window].base_lo_reg,
  1894. mv64360_64bit_windows[window].size_reg);
  1895. if ((mv64360_64bit_windows[window].base_lo_reg != 0) &&
  1896. (mv64360_64bit_windows[window].size_reg != 0)) {
  1897. if ((mv64360_64bit_windows[window].extra & MV64x60_EXTRA_MASK)
  1898. == MV64x60_EXTRA_PCIACC_ENAB)
  1899. mv64x60_clr_bits(bh,
  1900. mv64360_64bit_windows[window].base_lo_reg,
  1901. (1 << (mv64360_64bit_windows[window].extra &
  1902. 0x1f)));
  1903. else
  1904. printk(KERN_ERR "mv64360_disable: %s\n",
  1905. "64bit table corrupted");
  1906. }
  1907. return;
  1908. }
  1909. /*
  1910. * mv64360_disable_all_windows()
  1911. *
  1912. * The MV64360 has a few windows that aren't represented in the table of
  1913. * windows at the top of this file. This routine turns all of them off
  1914. * except for the memory controller windows, of course.
  1915. */
  1916. static void __init
  1917. mv64360_disable_all_windows(struct mv64x60_handle *bh,
  1918. struct mv64x60_setup_info *si)
  1919. {
  1920. u32 preserve, i;
  1921. /* Disable 32bit windows (don't disable cpu->mem windows) */
  1922. for (i=MV64x60_CPU2DEV_0_WIN; i<MV64x60_32BIT_WIN_COUNT; i++) {
  1923. if (i < 32)
  1924. preserve = si->window_preserve_mask_32_lo & (1 << i);
  1925. else
  1926. preserve = si->window_preserve_mask_32_hi & (1<<(i-32));
  1927. if (!preserve)
  1928. mv64360_disable_window_32bit(bh, i);
  1929. }
  1930. /* Disable 64bit windows */
  1931. for (i=0; i<MV64x60_64BIT_WIN_COUNT; i++)
  1932. if (!(si->window_preserve_mask_64 & (1<<i)))
  1933. mv64360_disable_window_64bit(bh, i);
  1934. /* Turn off PCI->MEM access cntl wins not in mv64360_64bit_windows[] */
  1935. mv64x60_clr_bits(bh, MV64x60_PCI0_ACC_CNTL_4_BASE_LO, 0);
  1936. mv64x60_clr_bits(bh, MV64x60_PCI0_ACC_CNTL_5_BASE_LO, 0);
  1937. mv64x60_clr_bits(bh, MV64x60_PCI1_ACC_CNTL_4_BASE_LO, 0);
  1938. mv64x60_clr_bits(bh, MV64x60_PCI1_ACC_CNTL_5_BASE_LO, 0);
  1939. /* Disable all PCI-><whatever> windows */
  1940. mv64x60_set_bits(bh, MV64x60_PCI0_BAR_ENABLE, 0x0000f9ff);
  1941. mv64x60_set_bits(bh, MV64x60_PCI1_BAR_ENABLE, 0x0000f9ff);
  1942. return;
  1943. }
  1944. /*
  1945. * mv64360_config_io2mem_windows()
  1946. *
  1947. * ENET, MPSC, and IDMA ctlrs on the MV64[34]60 have separate windows that
  1948. * must be set up so that the respective ctlr can access system memory.
  1949. */
  1950. static u32 enet_tab[MV64x60_CPU2MEM_WINDOWS] __initdata = {
  1951. MV64x60_ENET2MEM_0_WIN, MV64x60_ENET2MEM_1_WIN,
  1952. MV64x60_ENET2MEM_2_WIN, MV64x60_ENET2MEM_3_WIN,
  1953. };
  1954. static u32 mpsc_tab[MV64x60_CPU2MEM_WINDOWS] __initdata = {
  1955. MV64x60_MPSC2MEM_0_WIN, MV64x60_MPSC2MEM_1_WIN,
  1956. MV64x60_MPSC2MEM_2_WIN, MV64x60_MPSC2MEM_3_WIN,
  1957. };
  1958. static u32 idma_tab[MV64x60_CPU2MEM_WINDOWS] __initdata = {
  1959. MV64x60_IDMA2MEM_0_WIN, MV64x60_IDMA2MEM_1_WIN,
  1960. MV64x60_IDMA2MEM_2_WIN, MV64x60_IDMA2MEM_3_WIN,
  1961. };
  1962. static u32 dram_selects[MV64x60_CPU2MEM_WINDOWS] __initdata =
  1963. { 0xe, 0xd, 0xb, 0x7 };
  1964. static void __init
  1965. mv64360_config_io2mem_windows(struct mv64x60_handle *bh,
  1966. struct mv64x60_setup_info *si,
  1967. u32 mem_windows[MV64x60_CPU2MEM_WINDOWS][2])
  1968. {
  1969. u32 i, win;
  1970. pr_debug("config_io2regs_windows: enet, mpsc, idma -> bridge regs\n");
  1971. mv64x60_write(bh, MV64360_ENET2MEM_ACC_PROT_0, 0);
  1972. mv64x60_write(bh, MV64360_ENET2MEM_ACC_PROT_1, 0);
  1973. mv64x60_write(bh, MV64360_ENET2MEM_ACC_PROT_2, 0);
  1974. mv64x60_write(bh, MV64360_MPSC2MEM_ACC_PROT_0, 0);
  1975. mv64x60_write(bh, MV64360_MPSC2MEM_ACC_PROT_1, 0);
  1976. mv64x60_write(bh, MV64360_IDMA2MEM_ACC_PROT_0, 0);
  1977. mv64x60_write(bh, MV64360_IDMA2MEM_ACC_PROT_1, 0);
  1978. mv64x60_write(bh, MV64360_IDMA2MEM_ACC_PROT_2, 0);
  1979. mv64x60_write(bh, MV64360_IDMA2MEM_ACC_PROT_3, 0);
  1980. /* Assume that mem ctlr has no more windows than embedded I/O ctlr */
  1981. for (win=MV64x60_CPU2MEM_0_WIN,i=0;win<=MV64x60_CPU2MEM_3_WIN;win++,i++)
  1982. if (bh->ci->is_enabled_32bit(bh, win)) {
  1983. mv64x60_set_32bit_window(bh, enet_tab[i],
  1984. mem_windows[i][0], mem_windows[i][1],
  1985. (dram_selects[i] << 8) |
  1986. (si->enet_options[i] & 0x3000));
  1987. bh->ci->enable_window_32bit(bh, enet_tab[i]);
  1988. /* Give enet r/w access to memory region */
  1989. mv64x60_set_bits(bh, MV64360_ENET2MEM_ACC_PROT_0,
  1990. (0x3 << (i << 1)));
  1991. mv64x60_set_bits(bh, MV64360_ENET2MEM_ACC_PROT_1,
  1992. (0x3 << (i << 1)));
  1993. mv64x60_set_bits(bh, MV64360_ENET2MEM_ACC_PROT_2,
  1994. (0x3 << (i << 1)));
  1995. mv64x60_set_32bit_window(bh, mpsc_tab[i],
  1996. mem_windows[i][0], mem_windows[i][1],
  1997. (dram_selects[i] << 8) |
  1998. (si->mpsc_options[i] & 0x3000));
  1999. bh->ci->enable_window_32bit(bh, mpsc_tab[i]);
  2000. /* Give mpsc r/w access to memory region */
  2001. mv64x60_set_bits(bh, MV64360_MPSC2MEM_ACC_PROT_0,
  2002. (0x3 << (i << 1)));
  2003. mv64x60_set_bits(bh, MV64360_MPSC2MEM_ACC_PROT_1,
  2004. (0x3 << (i << 1)));
  2005. mv64x60_set_32bit_window(bh, idma_tab[i],
  2006. mem_windows[i][0], mem_windows[i][1],
  2007. (dram_selects[i] << 8) |
  2008. (si->idma_options[i] & 0x3000));
  2009. bh->ci->enable_window_32bit(bh, idma_tab[i]);
  2010. /* Give idma r/w access to memory region */
  2011. mv64x60_set_bits(bh, MV64360_IDMA2MEM_ACC_PROT_0,
  2012. (0x3 << (i << 1)));
  2013. mv64x60_set_bits(bh, MV64360_IDMA2MEM_ACC_PROT_1,
  2014. (0x3 << (i << 1)));
  2015. mv64x60_set_bits(bh, MV64360_IDMA2MEM_ACC_PROT_2,
  2016. (0x3 << (i << 1)));
  2017. mv64x60_set_bits(bh, MV64360_IDMA2MEM_ACC_PROT_3,
  2018. (0x3 << (i << 1)));
  2019. }
  2020. return;
  2021. }
  2022. /*
  2023. * mv64360_set_mpsc2regs_window()
  2024. *
  2025. * MPSC has a window to the bridge's internal registers. Call this routine
  2026. * to change that window so it doesn't conflict with the windows mapping the
  2027. * mpsc to system memory.
  2028. */
  2029. static void __init
  2030. mv64360_set_mpsc2regs_window(struct mv64x60_handle *bh, u32 base)
  2031. {
  2032. pr_debug("set mpsc->internal regs, base: 0x%x\n", base);
  2033. mv64x60_write(bh, MV64360_MPSC2REGS_BASE, base & 0xffff0000);
  2034. return;
  2035. }
  2036. /*
  2037. * mv64360_chip_specific_init()
  2038. *
  2039. * No errata work arounds for the MV64360 implemented at this point.
  2040. */
  2041. static void __init
  2042. mv64360_chip_specific_init(struct mv64x60_handle *bh,
  2043. struct mv64x60_setup_info *si)
  2044. {
  2045. #ifdef CONFIG_SERIAL_MPSC
  2046. mv64x60_mpsc0_pdata.brg_can_tune = 1;
  2047. mv64x60_mpsc0_pdata.cache_mgmt = 1;
  2048. mv64x60_mpsc1_pdata.brg_can_tune = 1;
  2049. mv64x60_mpsc1_pdata.cache_mgmt = 1;
  2050. #endif
  2051. return;
  2052. }
  2053. /*
  2054. * mv64460_chip_specific_init()
  2055. *
  2056. * No errata work arounds for the MV64460 implemented at this point.
  2057. */
  2058. static void __init
  2059. mv64460_chip_specific_init(struct mv64x60_handle *bh,
  2060. struct mv64x60_setup_info *si)
  2061. {
  2062. #ifdef CONFIG_SERIAL_MPSC
  2063. mv64x60_mpsc0_pdata.brg_can_tune = 1;
  2064. mv64x60_mpsc1_pdata.brg_can_tune = 1;
  2065. #endif
  2066. return;
  2067. }