mv64x60.c 68 KB

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