mv64x60.c 69 KB

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