mv64x60.c 69 KB

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