pplus.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903
  1. /*
  2. * Board and PCI setup routines for MCG PowerPlus
  3. *
  4. * Author: Randy Vinson <rvinson@mvista.com>
  5. *
  6. * Derived from original PowerPlus PReP work by
  7. * Cort Dougan, Johnnie Peters, Matt Porter, and
  8. * Troy Benjegerdes.
  9. *
  10. * 2001-2004 (c) MontaVista, Software, Inc. This file is licensed under
  11. * the terms of the GNU General Public License version 2. This program
  12. * is licensed "as is" without any warranty of any kind, whether express
  13. * or implied.
  14. */
  15. #include <linux/config.h>
  16. #include <linux/kernel.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/init.h>
  19. #include <linux/ioport.h>
  20. #include <linux/console.h>
  21. #include <linux/pci.h>
  22. #include <linux/ide.h>
  23. #include <linux/seq_file.h>
  24. #include <linux/root_dev.h>
  25. #include <asm/system.h>
  26. #include <asm/io.h>
  27. #include <asm/pgtable.h>
  28. #include <asm/dma.h>
  29. #include <asm/machdep.h>
  30. #include <asm/prep_nvram.h>
  31. #include <asm/vga.h>
  32. #include <asm/i8259.h>
  33. #include <asm/open_pic.h>
  34. #include <asm/hawk.h>
  35. #include <asm/todc.h>
  36. #include <asm/bootinfo.h>
  37. #include <asm/kgdb.h>
  38. #include <asm/reg.h>
  39. #include "pplus.h"
  40. #undef DUMP_DBATS
  41. TODC_ALLOC();
  42. extern void pplus_setup_hose(void);
  43. extern void pplus_set_VIA_IDE_native(void);
  44. extern unsigned long loops_per_jiffy;
  45. unsigned char *Motherboard_map_name;
  46. /* Tables for known hardware */
  47. /* Motorola Mesquite */
  48. static inline int
  49. mesquite_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
  50. {
  51. static char pci_irq_table[][4] =
  52. /*
  53. * MPIC interrupts for various IDSEL values (MPIC IRQ0 =
  54. * Linux IRQ16 (to leave room for ISA IRQs at 0-15).
  55. * PCI IDSEL/INTPIN->INTLINE
  56. * A B C D
  57. */
  58. {
  59. {18, 0, 0, 0}, /* IDSEL 14 - Enet 0 */
  60. { 0, 0, 0, 0}, /* IDSEL 15 - unused */
  61. {19, 19, 19, 19}, /* IDSEL 16 - PMC Slot 1 */
  62. { 0, 0, 0, 0}, /* IDSEL 17 - unused */
  63. { 0, 0, 0, 0}, /* IDSEL 18 - unused */
  64. { 0, 0, 0, 0}, /* IDSEL 19 - unused */
  65. {24, 25, 26, 27}, /* IDSEL 20 - P2P bridge (to cPCI 1) */
  66. { 0, 0, 0, 0}, /* IDSEL 21 - unused */
  67. {28, 29, 30, 31} /* IDSEL 22 - P2P bridge (to cPCI 2) */
  68. };
  69. const long min_idsel = 14, max_idsel = 22, irqs_per_slot = 4;
  70. return PCI_IRQ_TABLE_LOOKUP;
  71. }
  72. /* Motorola Sitka */
  73. static inline int
  74. sitka_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
  75. {
  76. static char pci_irq_table[][4] =
  77. /*
  78. * MPIC interrupts for various IDSEL values (MPIC IRQ0 =
  79. * Linux IRQ16 (to leave room for ISA IRQs at 0-15).
  80. * PCI IDSEL/INTPIN->INTLINE
  81. * A B C D
  82. */
  83. {
  84. {18, 0, 0, 0}, /* IDSEL 14 - Enet 0 */
  85. { 0, 0, 0, 0}, /* IDSEL 15 - unused */
  86. {25, 26, 27, 28}, /* IDSEL 16 - PMC Slot 1 */
  87. {28, 25, 26, 27}, /* IDSEL 17 - PMC Slot 2 */
  88. { 0, 0, 0, 0}, /* IDSEL 18 - unused */
  89. { 0, 0, 0, 0}, /* IDSEL 19 - unused */
  90. {20, 0, 0, 0} /* IDSEL 20 - P2P bridge (to cPCI) */
  91. };
  92. const long min_idsel = 14, max_idsel = 20, irqs_per_slot = 4;
  93. return PCI_IRQ_TABLE_LOOKUP;
  94. }
  95. /* Motorola MTX */
  96. static inline int
  97. MTX_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
  98. {
  99. static char pci_irq_table[][4] =
  100. /*
  101. * MPIC interrupts for various IDSEL values (MPIC IRQ0 =
  102. * Linux IRQ16 (to leave room for ISA IRQs at 0-15).
  103. * PCI IDSEL/INTPIN->INTLINE
  104. * A B C D
  105. */
  106. {
  107. {19, 0, 0, 0}, /* IDSEL 12 - SCSI */
  108. { 0, 0, 0, 0}, /* IDSEL 13 - unused */
  109. {18, 0, 0, 0}, /* IDSEL 14 - Enet */
  110. { 0, 0, 0, 0}, /* IDSEL 15 - unused */
  111. {25, 26, 27, 28}, /* IDSEL 16 - PMC Slot 1 */
  112. {26, 27, 28, 25}, /* IDSEL 17 - PMC Slot 2 */
  113. {27, 28, 25, 26} /* IDSEL 18 - PCI Slot 3 */
  114. };
  115. const long min_idsel = 12, max_idsel = 18, irqs_per_slot = 4;
  116. return PCI_IRQ_TABLE_LOOKUP;
  117. }
  118. /* Motorola MTX Plus */
  119. /* Secondary bus interrupt routing is not supported yet */
  120. static inline int
  121. MTXplus_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
  122. {
  123. static char pci_irq_table[][4] =
  124. /*
  125. * MPIC interrupts for various IDSEL values (MPIC IRQ0 =
  126. * Linux IRQ16 (to leave room for ISA IRQs at 0-15).
  127. * PCI IDSEL/INTPIN->INTLINE
  128. * A B C D
  129. */
  130. {
  131. {19, 0, 0, 0}, /* IDSEL 12 - SCSI */
  132. { 0, 0, 0, 0}, /* IDSEL 13 - unused */
  133. {18, 0, 0, 0}, /* IDSEL 14 - Enet 1 */
  134. { 0, 0, 0, 0}, /* IDSEL 15 - unused */
  135. {25, 26, 27, 28}, /* IDSEL 16 - PCI Slot 1P */
  136. {26, 27, 28, 25}, /* IDSEL 17 - PCI Slot 2P */
  137. {27, 28, 25, 26}, /* IDSEL 18 - PCI Slot 3P */
  138. {26, 0, 0, 0}, /* IDSEL 19 - Enet 2 */
  139. { 0, 0, 0, 0} /* IDSEL 20 - P2P Bridge */
  140. };
  141. const long min_idsel = 12, max_idsel = 20, irqs_per_slot = 4;
  142. return PCI_IRQ_TABLE_LOOKUP;
  143. }
  144. static inline int
  145. Genesis2_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
  146. {
  147. /* 2600
  148. * Raven 31
  149. * ISA 11
  150. * SCSI 12 - IRQ3
  151. * Univ 13
  152. * eth 14 - IRQ2
  153. * VGA 15 - IRQ4
  154. * PMC1 16 - IRQ9,10,11,12 = PMC1 A-D
  155. * PMC2 17 - IRQ12,9,10,11 = A-D
  156. * SCSI2 18 - IRQ11
  157. * eth2 19 - IRQ10
  158. * PCIX 20 - IRQ9,10,11,12 = PCI A-D
  159. */
  160. /* 2400
  161. * Hawk 31
  162. * ISA 11
  163. * Univ 13
  164. * eth 14 - IRQ2
  165. * PMC1 16 - IRQ9,10,11,12 = PMC A-D
  166. * PMC2 17 - IRQ12,9,10,11 = PMC A-D
  167. * PCIX 20 - IRQ9,10,11,12 = PMC A-D
  168. */
  169. /* 2300
  170. * Raven 31
  171. * ISA 11
  172. * Univ 13
  173. * eth 14 - IRQ2
  174. * PMC1 16 - 9,10,11,12 = A-D
  175. * PMC2 17 - 9,10,11,12 = B,C,D,A
  176. */
  177. static char pci_irq_table[][4] =
  178. /*
  179. * MPIC interrupts for various IDSEL values (MPIC IRQ0 =
  180. * Linux IRQ16 (to leave room for ISA IRQs at 0-15).
  181. * PCI IDSEL/INTPIN->INTLINE
  182. * A B C D
  183. */
  184. {
  185. {19, 0, 0, 0}, /* IDSEL 12 - SCSI */
  186. { 0, 0, 0, 0}, /* IDSEL 13 - Universe PCI - VME */
  187. {18, 0, 0, 0}, /* IDSEL 14 - Enet 1 */
  188. { 0, 0, 0, 0}, /* IDSEL 15 - unused */
  189. {25, 26, 27, 28}, /* IDSEL 16 - PCI/PMC Slot 1P */
  190. {28, 25, 26, 27}, /* IDSEL 17 - PCI/PMC Slot 2P */
  191. {27, 28, 25, 26}, /* IDSEL 18 - PCI Slot 3P */
  192. {26, 0, 0, 0}, /* IDSEL 19 - Enet 2 */
  193. {25, 26, 27, 28} /* IDSEL 20 - P2P Bridge */
  194. };
  195. const long min_idsel = 12, max_idsel = 20, irqs_per_slot = 4;
  196. return PCI_IRQ_TABLE_LOOKUP;
  197. }
  198. #define MOTOROLA_CPUTYPE_REG 0x800
  199. #define MOTOROLA_BASETYPE_REG 0x803
  200. #define MPIC_RAVEN_ID 0x48010000
  201. #define MPIC_HAWK_ID 0x48030000
  202. #define MOT_PROC2_BIT 0x800
  203. static u_char pplus_openpic_initsenses[] __initdata = {
  204. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* MVME2600_INT_SIO */
  205. (IRQ_SENSE_EDGE | IRQ_POLARITY_NEGATIVE),/*MVME2600_INT_FALCN_ECC_ERR */
  206. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),/*MVME2600_INT_PCI_ETHERNET */
  207. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* MVME2600_INT_PCI_SCSI */
  208. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),/*MVME2600_INT_PCI_GRAPHICS */
  209. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* MVME2600_INT_PCI_VME0 */
  210. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* MVME2600_INT_PCI_VME1 */
  211. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* MVME2600_INT_PCI_VME2 */
  212. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* MVME2600_INT_PCI_VME3 */
  213. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* MVME2600_INT_PCI_INTA */
  214. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* MVME2600_INT_PCI_INTB */
  215. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* MVME2600_INT_PCI_INTC */
  216. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* MVME2600_INT_PCI_INTD */
  217. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* MVME2600_INT_LM_SIG0 */
  218. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* MVME2600_INT_LM_SIG1 */
  219. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),
  220. };
  221. int mot_entry = -1;
  222. int prep_keybd_present = 1;
  223. int mot_multi = 0;
  224. struct brd_info {
  225. /* 0x100 mask assumes for Raven and Hawk boards that the level/edge
  226. * are set */
  227. int cpu_type;
  228. /* 0x200 if this board has a Hawk chip. */
  229. int base_type;
  230. /* or'ed with 0x80 if this board should be checked for multi CPU */
  231. int max_cpu;
  232. const char *name;
  233. int (*map_irq) (struct pci_dev *, unsigned char, unsigned char);
  234. };
  235. struct brd_info mot_info[] = {
  236. {0x300, 0x00, 0x00, "MVME 2400", Genesis2_map_irq},
  237. {0x1E0, 0xE0, 0x00, "Mesquite cPCI (MCP750)", mesquite_map_irq},
  238. {0x1E0, 0xE1, 0x00, "Sitka cPCI (MCPN750)", sitka_map_irq},
  239. {0x1E0, 0xE2, 0x00, "Mesquite cPCI (MCP750) w/ HAC", mesquite_map_irq},
  240. {0x1E0, 0xF6, 0x80, "MTX Plus", MTXplus_map_irq},
  241. {0x1E0, 0xF6, 0x81, "Dual MTX Plus", MTXplus_map_irq},
  242. {0x1E0, 0xF7, 0x80, "MTX wo/ Parallel Port", MTX_map_irq},
  243. {0x1E0, 0xF7, 0x81, "Dual MTX wo/ Parallel Port", MTX_map_irq},
  244. {0x1E0, 0xF8, 0x80, "MTX w/ Parallel Port", MTX_map_irq},
  245. {0x1E0, 0xF8, 0x81, "Dual MTX w/ Parallel Port", MTX_map_irq},
  246. {0x1E0, 0xF9, 0x00, "MVME 2300", Genesis2_map_irq},
  247. {0x1E0, 0xFA, 0x00, "MVME 2300SC/2600", Genesis2_map_irq},
  248. {0x1E0, 0xFB, 0x00, "MVME 2600 with MVME712M", Genesis2_map_irq},
  249. {0x1E0, 0xFC, 0x00, "MVME 2600/2700 with MVME761", Genesis2_map_irq},
  250. {0x1E0, 0xFD, 0x80, "MVME 3600 with MVME712M", Genesis2_map_irq},
  251. {0x1E0, 0xFD, 0x81, "MVME 4600 with MVME712M", Genesis2_map_irq},
  252. {0x1E0, 0xFE, 0x80, "MVME 3600 with MVME761", Genesis2_map_irq},
  253. {0x1E0, 0xFE, 0x81, "MVME 4600 with MVME761", Genesis2_map_irq},
  254. {0x000, 0x00, 0x00, "", NULL}
  255. };
  256. void __init pplus_set_board_type(void)
  257. {
  258. unsigned char cpu_type;
  259. unsigned char base_mod;
  260. int entry;
  261. unsigned short devid;
  262. unsigned long *ProcInfo = NULL;
  263. cpu_type = inb(MOTOROLA_CPUTYPE_REG) & 0xF0;
  264. base_mod = inb(MOTOROLA_BASETYPE_REG);
  265. early_read_config_word(0, 0, 0, PCI_VENDOR_ID, &devid);
  266. for (entry = 0; mot_info[entry].cpu_type != 0; entry++) {
  267. /* Check for Hawk chip */
  268. if (mot_info[entry].cpu_type & 0x200) {
  269. if (devid != PCI_DEVICE_ID_MOTOROLA_HAWK)
  270. continue;
  271. } else {
  272. /* store the system config register for later use. */
  273. ProcInfo =
  274. (unsigned long *)ioremap(PPLUS_SYS_CONFIG_REG, 4);
  275. /* Check non hawk boards */
  276. if ((mot_info[entry].cpu_type & 0xff) != cpu_type)
  277. continue;
  278. if (mot_info[entry].base_type == 0) {
  279. mot_entry = entry;
  280. break;
  281. }
  282. if (mot_info[entry].base_type != base_mod)
  283. continue;
  284. }
  285. if (!(mot_info[entry].max_cpu & 0x80)) {
  286. mot_entry = entry;
  287. break;
  288. }
  289. /* processor 1 not present and max processor zero indicated */
  290. if ((*ProcInfo & MOT_PROC2_BIT)
  291. && !(mot_info[entry].max_cpu & 0x7f)) {
  292. mot_entry = entry;
  293. break;
  294. }
  295. /* processor 1 present and max processor zero indicated */
  296. if (!(*ProcInfo & MOT_PROC2_BIT)
  297. && (mot_info[entry].max_cpu & 0x7f)) {
  298. mot_entry = entry;
  299. break;
  300. }
  301. /* Indicate to system if this is a multiprocessor board */
  302. if (!(*ProcInfo & MOT_PROC2_BIT))
  303. mot_multi = 1;
  304. }
  305. if (mot_entry == -1)
  306. /* No particular cpu type found - assume Mesquite (MCP750) */
  307. mot_entry = 1;
  308. Motherboard_map_name = (unsigned char *)mot_info[mot_entry].name;
  309. ppc_md.pci_map_irq = mot_info[mot_entry].map_irq;
  310. }
  311. void __init pplus_pib_init(void)
  312. {
  313. unsigned char reg;
  314. unsigned short short_reg;
  315. struct pci_dev *dev = NULL;
  316. /*
  317. * Perform specific configuration for the Via Tech or
  318. * or Winbond PCI-ISA-Bridge part.
  319. */
  320. if ((dev = pci_get_device(PCI_VENDOR_ID_VIA,
  321. PCI_DEVICE_ID_VIA_82C586_1, dev))) {
  322. /*
  323. * PPCBUG does not set the enable bits
  324. * for the IDE device. Force them on here.
  325. */
  326. pci_read_config_byte(dev, 0x40, &reg);
  327. reg |= 0x03; /* IDE: Chip Enable Bits */
  328. pci_write_config_byte(dev, 0x40, reg);
  329. }
  330. if ((dev = pci_get_device(PCI_VENDOR_ID_VIA,
  331. PCI_DEVICE_ID_VIA_82C586_2,
  332. dev)) && (dev->devfn = 0x5a)) {
  333. /* Force correct USB interrupt */
  334. dev->irq = 11;
  335. pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
  336. }
  337. if ((dev = pci_get_device(PCI_VENDOR_ID_WINBOND,
  338. PCI_DEVICE_ID_WINBOND_83C553, dev))) {
  339. /* Clear PCI Interrupt Routing Control Register. */
  340. short_reg = 0x0000;
  341. pci_write_config_word(dev, 0x44, short_reg);
  342. /* Route IDE interrupts to IRQ 14 */
  343. reg = 0xEE;
  344. pci_write_config_byte(dev, 0x43, reg);
  345. }
  346. if ((dev = pci_get_device(PCI_VENDOR_ID_WINBOND,
  347. PCI_DEVICE_ID_WINBOND_82C105, dev))) {
  348. /*
  349. * Disable LEGIRQ mode so PCI INTS are routed
  350. * directly to the 8259 and enable both channels
  351. */
  352. pci_write_config_dword(dev, 0x40, 0x10ff0033);
  353. /* Force correct IDE interrupt */
  354. dev->irq = 14;
  355. pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
  356. }
  357. pci_dev_put(dev);
  358. }
  359. void __init pplus_set_VIA_IDE_legacy(void)
  360. {
  361. unsigned short vend, dev;
  362. early_read_config_word(0, 0, PCI_DEVFN(0xb, 1), PCI_VENDOR_ID, &vend);
  363. early_read_config_word(0, 0, PCI_DEVFN(0xb, 1), PCI_DEVICE_ID, &dev);
  364. if ((vend == PCI_VENDOR_ID_VIA) &&
  365. (dev == PCI_DEVICE_ID_VIA_82C586_1)) {
  366. unsigned char temp;
  367. /* put back original "standard" port base addresses */
  368. early_write_config_dword(0, 0, PCI_DEVFN(0xb, 1),
  369. PCI_BASE_ADDRESS_0, 0x1f1);
  370. early_write_config_dword(0, 0, PCI_DEVFN(0xb, 1),
  371. PCI_BASE_ADDRESS_1, 0x3f5);
  372. early_write_config_dword(0, 0, PCI_DEVFN(0xb, 1),
  373. PCI_BASE_ADDRESS_2, 0x171);
  374. early_write_config_dword(0, 0, PCI_DEVFN(0xb, 1),
  375. PCI_BASE_ADDRESS_3, 0x375);
  376. early_write_config_dword(0, 0, PCI_DEVFN(0xb, 1),
  377. PCI_BASE_ADDRESS_4, 0xcc01);
  378. /* put into legacy mode */
  379. early_read_config_byte(0, 0, PCI_DEVFN(0xb, 1), PCI_CLASS_PROG,
  380. &temp);
  381. temp &= ~0x05;
  382. early_write_config_byte(0, 0, PCI_DEVFN(0xb, 1), PCI_CLASS_PROG,
  383. temp);
  384. }
  385. }
  386. void pplus_set_VIA_IDE_native(void)
  387. {
  388. unsigned short vend, dev;
  389. early_read_config_word(0, 0, PCI_DEVFN(0xb, 1), PCI_VENDOR_ID, &vend);
  390. early_read_config_word(0, 0, PCI_DEVFN(0xb, 1), PCI_DEVICE_ID, &dev);
  391. if ((vend == PCI_VENDOR_ID_VIA) &&
  392. (dev == PCI_DEVICE_ID_VIA_82C586_1)) {
  393. unsigned char temp;
  394. /* put into native mode */
  395. early_read_config_byte(0, 0, PCI_DEVFN(0xb, 1), PCI_CLASS_PROG,
  396. &temp);
  397. temp |= 0x05;
  398. early_write_config_byte(0, 0, PCI_DEVFN(0xb, 1), PCI_CLASS_PROG,
  399. temp);
  400. }
  401. }
  402. void __init pplus_pcibios_fixup(void)
  403. {
  404. unsigned char reg;
  405. unsigned short devid;
  406. unsigned char base_mod;
  407. printk(KERN_INFO "Setting PCI interrupts for a \"%s\"\n",
  408. Motherboard_map_name);
  409. /* Setup the Winbond or Via PIB */
  410. pplus_pib_init();
  411. /* Set up floppy in PS/2 mode */
  412. outb(0x09, SIO_CONFIG_RA);
  413. reg = inb(SIO_CONFIG_RD);
  414. reg = (reg & 0x3F) | 0x40;
  415. outb(reg, SIO_CONFIG_RD);
  416. outb(reg, SIO_CONFIG_RD); /* Have to write twice to change! */
  417. /* This is a hack. If this is a 2300 or 2400 mot board then there is
  418. * no keyboard controller and we have to indicate that.
  419. */
  420. early_read_config_word(0, 0, 0, PCI_VENDOR_ID, &devid);
  421. base_mod = inb(MOTOROLA_BASETYPE_REG);
  422. if ((devid == PCI_DEVICE_ID_MOTOROLA_HAWK) ||
  423. (base_mod == 0xF9) || (base_mod == 0xFA) || (base_mod == 0xE1))
  424. prep_keybd_present = 0;
  425. }
  426. void __init pplus_find_bridges(void)
  427. {
  428. struct pci_controller *hose;
  429. hose = pcibios_alloc_controller();
  430. if (!hose)
  431. return;
  432. hose->first_busno = 0;
  433. hose->last_busno = 0xff;
  434. hose->pci_mem_offset = PREP_ISA_MEM_BASE;
  435. hose->io_base_virt = (void *)PREP_ISA_IO_BASE;
  436. pci_init_resource(&hose->io_resource, PPLUS_PCI_IO_START,
  437. PPLUS_PCI_IO_END, IORESOURCE_IO, "PCI host bridge");
  438. pci_init_resource(&hose->mem_resources[0], PPLUS_PROC_PCI_MEM_START,
  439. PPLUS_PROC_PCI_MEM_END, IORESOURCE_MEM,
  440. "PCI host bridge");
  441. hose->io_space.start = PPLUS_PCI_IO_START;
  442. hose->io_space.end = PPLUS_PCI_IO_END;
  443. hose->mem_space.start = PPLUS_PCI_MEM_START;
  444. hose->mem_space.end = PPLUS_PCI_MEM_END - HAWK_MPIC_SIZE;
  445. if (hawk_init(hose, PPLUS_HAWK_PPC_REG_BASE, PPLUS_PROC_PCI_MEM_START,
  446. PPLUS_PROC_PCI_MEM_END - HAWK_MPIC_SIZE,
  447. PPLUS_PROC_PCI_IO_START, PPLUS_PROC_PCI_IO_END,
  448. PPLUS_PROC_PCI_MEM_END - HAWK_MPIC_SIZE + 1)
  449. != 0) {
  450. printk(KERN_CRIT "Could not initialize host bridge\n");
  451. }
  452. pplus_set_VIA_IDE_legacy();
  453. hose->last_busno = pciauto_bus_scan(hose, hose->first_busno);
  454. ppc_md.pcibios_fixup = pplus_pcibios_fixup;
  455. ppc_md.pci_swizzle = common_swizzle;
  456. }
  457. static int pplus_show_cpuinfo(struct seq_file *m)
  458. {
  459. seq_printf(m, "vendor\t\t: Motorola MCG\n");
  460. seq_printf(m, "machine\t\t: %s\n", Motherboard_map_name);
  461. return 0;
  462. }
  463. static void __init pplus_setup_arch(void)
  464. {
  465. struct pci_controller *hose;
  466. if (ppc_md.progress)
  467. ppc_md.progress("pplus_setup_arch: enter", 0);
  468. /* init to some ~sane value until calibrate_delay() runs */
  469. loops_per_jiffy = 50000000;
  470. if (ppc_md.progress)
  471. ppc_md.progress("pplus_setup_arch: find_bridges", 0);
  472. /* Setup PCI host bridge */
  473. pplus_find_bridges();
  474. hose = pci_bus_to_hose(0);
  475. isa_io_base = (ulong) hose->io_base_virt;
  476. if (ppc_md.progress)
  477. ppc_md.progress("pplus_setup_arch: set_board_type", 0);
  478. pplus_set_board_type();
  479. /* Enable L2. Assume we don't need to flush -- Cort */
  480. *(unsigned char *)(PPLUS_L2_CONTROL_REG) |= 3;
  481. #ifdef CONFIG_BLK_DEV_INITRD
  482. if (initrd_start)
  483. ROOT_DEV = Root_RAM0;
  484. else
  485. #endif
  486. #ifdef CONFIG_ROOT_NFS
  487. ROOT_DEV = Root_NFS;
  488. #else
  489. ROOT_DEV = Root_SDA2;
  490. #endif
  491. printk(KERN_INFO "Motorola PowerPlus Platform\n");
  492. printk(KERN_INFO
  493. "Port by MontaVista Software, Inc. (source@mvista.com)\n");
  494. #ifdef CONFIG_VGA_CONSOLE
  495. /* remap the VGA memory */
  496. vgacon_remap_base = (unsigned long)ioremap(PPLUS_ISA_MEM_BASE,
  497. 0x08000000);
  498. conswitchp = &vga_con;
  499. #endif
  500. #ifdef CONFIG_PPCBUG_NVRAM
  501. /* Read in NVRAM data */
  502. init_prep_nvram();
  503. /* if no bootargs, look in NVRAM */
  504. if (cmd_line[0] == '\0') {
  505. char *bootargs;
  506. bootargs = prep_nvram_get_var("bootargs");
  507. if (bootargs != NULL) {
  508. strcpy(cmd_line, bootargs);
  509. /* again.. */
  510. strcpy(saved_command_line, cmd_line);
  511. }
  512. }
  513. #endif
  514. if (ppc_md.progress)
  515. ppc_md.progress("pplus_setup_arch: exit", 0);
  516. }
  517. static void pplus_restart(char *cmd)
  518. {
  519. unsigned long i = 10000;
  520. local_irq_disable();
  521. /* set VIA IDE controller into native mode */
  522. pplus_set_VIA_IDE_native();
  523. /* set exception prefix high - to the prom */
  524. _nmask_and_or_msr(0, MSR_IP);
  525. /* make sure bit 0 (reset) is a 0 */
  526. outb(inb(0x92) & ~1L, 0x92);
  527. /* signal a reset to system control port A - soft reset */
  528. outb(inb(0x92) | 1, 0x92);
  529. while (i != 0)
  530. i++;
  531. panic("restart failed\n");
  532. }
  533. static void pplus_halt(void)
  534. {
  535. /* set exception prefix high - to the prom */
  536. _nmask_and_or_msr(MSR_EE, MSR_IP);
  537. /* make sure bit 0 (reset) is a 0 */
  538. outb(inb(0x92) & ~1L, 0x92);
  539. /* signal a reset to system control port A - soft reset */
  540. outb(inb(0x92) | 1, 0x92);
  541. while (1) ;
  542. /*
  543. * Not reached
  544. */
  545. }
  546. static void pplus_power_off(void)
  547. {
  548. pplus_halt();
  549. }
  550. static void __init pplus_init_IRQ(void)
  551. {
  552. int i;
  553. if (ppc_md.progress)
  554. ppc_md.progress("init_irq: enter", 0);
  555. OpenPIC_InitSenses = pplus_openpic_initsenses;
  556. OpenPIC_NumInitSenses = sizeof(pplus_openpic_initsenses);
  557. if (OpenPIC_Addr != NULL) {
  558. openpic_set_sources(0, 16, OpenPIC_Addr + 0x10000);
  559. openpic_init(NUM_8259_INTERRUPTS);
  560. openpic_hookup_cascade(NUM_8259_INTERRUPTS, "82c59 cascade",
  561. i8259_irq);
  562. ppc_md.get_irq = openpic_get_irq;
  563. }
  564. i8259_init(0, 0);
  565. if (ppc_md.progress)
  566. ppc_md.progress("init_irq: exit", 0);
  567. }
  568. #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
  569. /*
  570. * IDE stuff.
  571. */
  572. static int pplus_ide_default_irq(unsigned long base)
  573. {
  574. switch (base) {
  575. case 0x1f0:
  576. return 14;
  577. case 0x170:
  578. return 15;
  579. default:
  580. return 0;
  581. }
  582. }
  583. static unsigned long pplus_ide_default_io_base(int index)
  584. {
  585. switch (index) {
  586. case 0:
  587. return 0x1f0;
  588. case 1:
  589. return 0x170;
  590. default:
  591. return 0;
  592. }
  593. }
  594. static void __init
  595. pplus_ide_init_hwif_ports(hw_regs_t * hw, unsigned long data_port,
  596. unsigned long ctrl_port, int *irq)
  597. {
  598. unsigned long reg = data_port;
  599. int i;
  600. for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) {
  601. hw->io_ports[i] = reg;
  602. reg += 1;
  603. }
  604. if (ctrl_port)
  605. hw->io_ports[IDE_CONTROL_OFFSET] = ctrl_port;
  606. else
  607. hw->io_ports[IDE_CONTROL_OFFSET] =
  608. hw->io_ports[IDE_DATA_OFFSET] + 0x206;
  609. if (irq != NULL)
  610. *irq = pplus_ide_default_irq(data_port);
  611. }
  612. #endif
  613. #ifdef CONFIG_SMP
  614. /* PowerPlus (MTX) support */
  615. static int __init smp_pplus_probe(void)
  616. {
  617. extern int mot_multi;
  618. if (mot_multi) {
  619. openpic_request_IPIs();
  620. smp_hw_index[1] = 1;
  621. return 2;
  622. }
  623. return 1;
  624. }
  625. static void __init smp_pplus_kick_cpu(int nr)
  626. {
  627. *(unsigned long *)KERNELBASE = nr;
  628. asm volatile ("dcbf 0,%0"::"r" (KERNELBASE):"memory");
  629. printk(KERN_INFO "CPU1 reset, waiting\n");
  630. }
  631. static void __init smp_pplus_setup_cpu(int cpu_nr)
  632. {
  633. if (OpenPIC_Addr)
  634. do_openpic_setup_cpu();
  635. }
  636. static struct smp_ops_t pplus_smp_ops = {
  637. smp_openpic_message_pass,
  638. smp_pplus_probe,
  639. smp_pplus_kick_cpu,
  640. smp_pplus_setup_cpu,
  641. .give_timebase = smp_generic_give_timebase,
  642. .take_timebase = smp_generic_take_timebase,
  643. };
  644. #endif /* CONFIG_SMP */
  645. #ifdef DUMP_DBATS
  646. static void print_dbat(int idx, u32 bat)
  647. {
  648. char str[64];
  649. sprintf(str, "DBAT%c%c = 0x%08x\n",
  650. (char)((idx - DBAT0U) / 2) + '0', (idx & 1) ? 'L' : 'U', bat);
  651. ppc_md.progress(str, 0);
  652. }
  653. #define DUMP_DBAT(x) \
  654. do { \
  655. u32 __temp = mfspr(x);\
  656. print_dbat(x, __temp); \
  657. } while (0)
  658. static void dump_dbats(void)
  659. {
  660. if (ppc_md.progress) {
  661. DUMP_DBAT(DBAT0U);
  662. DUMP_DBAT(DBAT0L);
  663. DUMP_DBAT(DBAT1U);
  664. DUMP_DBAT(DBAT1L);
  665. DUMP_DBAT(DBAT2U);
  666. DUMP_DBAT(DBAT2L);
  667. DUMP_DBAT(DBAT3U);
  668. DUMP_DBAT(DBAT3L);
  669. }
  670. }
  671. #endif
  672. static unsigned long __init pplus_find_end_of_memory(void)
  673. {
  674. unsigned long total;
  675. if (ppc_md.progress)
  676. ppc_md.progress("pplus_find_end_of_memory", 0);
  677. #ifdef DUMP_DBATS
  678. dump_dbats();
  679. #endif
  680. total = hawk_get_mem_size(PPLUS_HAWK_SMC_BASE);
  681. return (total);
  682. }
  683. static void __init pplus_map_io(void)
  684. {
  685. io_block_mapping(PPLUS_ISA_IO_BASE, PPLUS_ISA_IO_BASE, 0x10000000,
  686. _PAGE_IO);
  687. io_block_mapping(0xfef80000, 0xfef80000, 0x00080000, _PAGE_IO);
  688. }
  689. static void __init pplus_init2(void)
  690. {
  691. #ifdef CONFIG_NVRAM
  692. request_region(PREP_NVRAM_AS0, 0x8, "nvram");
  693. #endif
  694. request_region(0x20, 0x20, "pic1");
  695. request_region(0xa0, 0x20, "pic2");
  696. request_region(0x00, 0x20, "dma1");
  697. request_region(0x40, 0x20, "timer");
  698. request_region(0x80, 0x10, "dma page reg");
  699. request_region(0xc0, 0x20, "dma2");
  700. }
  701. /*
  702. * Set BAT 2 to access 0x8000000 so progress messages will work and set BAT 3
  703. * to 0xf0000000 to access Falcon/Raven or Hawk registers
  704. */
  705. static __inline__ void pplus_set_bat(void)
  706. {
  707. /* wait for all outstanding memory accesses to complete */
  708. mb();
  709. /* setup DBATs */
  710. mtspr(SPRN_DBAT2U, 0x80001ffe);
  711. mtspr(SPRN_DBAT2L, 0x8000002a);
  712. mtspr(SPRN_DBAT3U, 0xf0001ffe);
  713. mtspr(SPRN_DBAT3L, 0xf000002a);
  714. /* wait for updates */
  715. mb();
  716. }
  717. void __init
  718. platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
  719. unsigned long r6, unsigned long r7)
  720. {
  721. parse_bootinfo(find_bootinfo());
  722. /* Map in board regs, etc. */
  723. pplus_set_bat();
  724. isa_io_base = PREP_ISA_IO_BASE;
  725. isa_mem_base = PREP_ISA_MEM_BASE;
  726. pci_dram_offset = PREP_PCI_DRAM_OFFSET;
  727. ISA_DMA_THRESHOLD = 0x00ffffff;
  728. DMA_MODE_READ = 0x44;
  729. DMA_MODE_WRITE = 0x48;
  730. ppc_do_canonicalize_irqs = 1;
  731. ppc_md.setup_arch = pplus_setup_arch;
  732. ppc_md.show_cpuinfo = pplus_show_cpuinfo;
  733. ppc_md.init_IRQ = pplus_init_IRQ;
  734. /* this gets changed later on if we have an OpenPIC -- Cort */
  735. ppc_md.get_irq = i8259_irq;
  736. ppc_md.init = pplus_init2;
  737. ppc_md.restart = pplus_restart;
  738. ppc_md.power_off = pplus_power_off;
  739. ppc_md.halt = pplus_halt;
  740. TODC_INIT(TODC_TYPE_MK48T59, PREP_NVRAM_AS0, PREP_NVRAM_AS1,
  741. PREP_NVRAM_DATA, 8);
  742. ppc_md.time_init = todc_time_init;
  743. ppc_md.set_rtc_time = todc_set_rtc_time;
  744. ppc_md.get_rtc_time = todc_get_rtc_time;
  745. ppc_md.calibrate_decr = todc_calibrate_decr;
  746. ppc_md.nvram_read_val = todc_m48txx_read_val;
  747. ppc_md.nvram_write_val = todc_m48txx_write_val;
  748. ppc_md.find_end_of_memory = pplus_find_end_of_memory;
  749. ppc_md.setup_io_mappings = pplus_map_io;
  750. #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
  751. ppc_ide_md.default_irq = pplus_ide_default_irq;
  752. ppc_ide_md.default_io_base = pplus_ide_default_io_base;
  753. ppc_ide_md.ide_init_hwif = pplus_ide_init_hwif_ports;
  754. #endif
  755. #ifdef CONFIG_SERIAL_TEXT_DEBUG
  756. ppc_md.progress = gen550_progress;
  757. #endif /* CONFIG_SERIAL_TEXT_DEBUG */
  758. #ifdef CONFIG_KGDB
  759. ppc_md.kgdb_map_scc = gen550_kgdb_map_scc;
  760. #endif
  761. #ifdef CONFIG_SMP
  762. smp_ops = &pplus_smp_ops;
  763. #endif /* CONFIG_SMP */
  764. }