mv64x60.c 68 KB

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