mv64x60.c 65 KB

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