mv64x60.c 68 KB

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