mv64x60.c 68 KB

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