mv64x60.c 69 KB

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