lopec.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. /*
  2. * arch/ppc/platforms/lopec.c
  3. *
  4. * Setup routines for the Motorola LoPEC.
  5. *
  6. * Author: Dan Cox
  7. * Maintainer: Tom Rini <trini@kernel.crashing.org>
  8. *
  9. * 2001-2004 (c) MontaVista, Software, Inc. This file is licensed under
  10. * the terms of the GNU General Public License version 2. This program
  11. * is licensed "as is" without any warranty of any kind, whether express
  12. * or implied.
  13. */
  14. #include <linux/config.h>
  15. #include <linux/types.h>
  16. #include <linux/delay.h>
  17. #include <linux/pci_ids.h>
  18. #include <linux/ioport.h>
  19. #include <linux/init.h>
  20. #include <linux/ide.h>
  21. #include <linux/seq_file.h>
  22. #include <linux/initrd.h>
  23. #include <linux/console.h>
  24. #include <linux/root_dev.h>
  25. #include <linux/pci.h>
  26. #include <asm/machdep.h>
  27. #include <asm/pci-bridge.h>
  28. #include <asm/io.h>
  29. #include <asm/open_pic.h>
  30. #include <asm/i8259.h>
  31. #include <asm/todc.h>
  32. #include <asm/bootinfo.h>
  33. #include <asm/mpc10x.h>
  34. #include <asm/hw_irq.h>
  35. #include <asm/prep_nvram.h>
  36. #include <asm/kgdb.h>
  37. /*
  38. * Define all of the IRQ senses and polarities. Taken from the
  39. * LoPEC Programmer's Reference Guide.
  40. */
  41. static u_char lopec_openpic_initsenses[16] __initdata = {
  42. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* IRQ 0 */
  43. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* IRQ 1 */
  44. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* IRQ 2 */
  45. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* IRQ 3 */
  46. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* IRQ 4 */
  47. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* IRQ 5 */
  48. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* IRQ 6 */
  49. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* IRQ 7 */
  50. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* IRQ 8 */
  51. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* IRQ 9 */
  52. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* IRQ 10 */
  53. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* IRQ 11 */
  54. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* IRQ 12 */
  55. (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* IRQ 13 */
  56. (IRQ_SENSE_EDGE | IRQ_POLARITY_NEGATIVE), /* IRQ 14 */
  57. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE) /* IRQ 15 */
  58. };
  59. static inline int __init
  60. lopec_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
  61. {
  62. int irq;
  63. static char pci_irq_table[][4] = {
  64. {16, 0, 0, 0}, /* ID 11 - Winbond */
  65. {22, 0, 0, 0}, /* ID 12 - SCSI */
  66. {0, 0, 0, 0}, /* ID 13 - nothing */
  67. {17, 0, 0, 0}, /* ID 14 - 82559 Ethernet */
  68. {27, 0, 0, 0}, /* ID 15 - USB */
  69. {23, 0, 0, 0}, /* ID 16 - PMC slot 1 */
  70. {24, 0, 0, 0}, /* ID 17 - PMC slot 2 */
  71. {25, 0, 0, 0}, /* ID 18 - PCI slot */
  72. {0, 0, 0, 0}, /* ID 19 - nothing */
  73. {0, 0, 0, 0}, /* ID 20 - nothing */
  74. {0, 0, 0, 0}, /* ID 21 - nothing */
  75. {0, 0, 0, 0}, /* ID 22 - nothing */
  76. {0, 0, 0, 0}, /* ID 23 - nothing */
  77. {0, 0, 0, 0}, /* ID 24 - PMC slot 1b */
  78. {0, 0, 0, 0}, /* ID 25 - nothing */
  79. {0, 0, 0, 0} /* ID 26 - PMC Slot 2b */
  80. };
  81. const long min_idsel = 11, max_idsel = 26, irqs_per_slot = 4;
  82. irq = PCI_IRQ_TABLE_LOOKUP;
  83. if (!irq)
  84. return 0;
  85. return irq;
  86. }
  87. static void __init
  88. lopec_setup_winbond_83553(struct pci_controller *hose)
  89. {
  90. int devfn;
  91. devfn = PCI_DEVFN(11,0);
  92. /* IDE interrupt routing (primary 14, secondary 15) */
  93. early_write_config_byte(hose, 0, devfn, 0x43, 0xef);
  94. /* PCI interrupt routing */
  95. early_write_config_word(hose, 0, devfn, 0x44, 0x0000);
  96. /* ISA-PCI address decoder */
  97. early_write_config_byte(hose, 0, devfn, 0x48, 0xf0);
  98. /* RTC, kb, not used in PPC */
  99. early_write_config_byte(hose, 0, devfn, 0x4d, 0x00);
  100. early_write_config_byte(hose, 0, devfn, 0x4e, 0x04);
  101. devfn = PCI_DEVFN(11, 1);
  102. early_write_config_byte(hose, 0, devfn, 0x09, 0x8f);
  103. early_write_config_dword(hose, 0, devfn, 0x40, 0x00ff0011);
  104. }
  105. static void __init
  106. lopec_find_bridges(void)
  107. {
  108. struct pci_controller *hose;
  109. hose = pcibios_alloc_controller();
  110. if (!hose)
  111. return;
  112. hose->first_busno = 0;
  113. hose->last_busno = 0xff;
  114. if (mpc10x_bridge_init(hose, MPC10X_MEM_MAP_B, MPC10X_MEM_MAP_B,
  115. MPC10X_MAPB_EUMB_BASE) == 0) {
  116. hose->mem_resources[0].end = 0xffffffff;
  117. lopec_setup_winbond_83553(hose);
  118. hose->last_busno = pciauto_bus_scan(hose, hose->first_busno);
  119. ppc_md.pci_swizzle = common_swizzle;
  120. ppc_md.pci_map_irq = lopec_map_irq;
  121. }
  122. }
  123. static int
  124. lopec_show_cpuinfo(struct seq_file *m)
  125. {
  126. seq_printf(m, "machine\t\t: Motorola LoPEC\n");
  127. return 0;
  128. }
  129. static u32
  130. lopec_irq_canonicalize(u32 irq)
  131. {
  132. if (irq == 2)
  133. return 9;
  134. else
  135. return irq;
  136. }
  137. static void
  138. lopec_restart(char *cmd)
  139. {
  140. #define LOPEC_SYSSTAT1 0xffe00000
  141. /* force a hard reset, if possible */
  142. unsigned char reg = *((unsigned char *) LOPEC_SYSSTAT1);
  143. reg |= 0x80;
  144. *((unsigned char *) LOPEC_SYSSTAT1) = reg;
  145. local_irq_disable();
  146. while(1);
  147. #undef LOPEC_SYSSTAT1
  148. }
  149. static void
  150. lopec_halt(void)
  151. {
  152. local_irq_disable();
  153. while(1);
  154. }
  155. static void
  156. lopec_power_off(void)
  157. {
  158. lopec_halt();
  159. }
  160. #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
  161. int lopec_ide_ports_known = 0;
  162. static unsigned long lopec_ide_regbase[MAX_HWIFS];
  163. static unsigned long lopec_ide_ctl_regbase[MAX_HWIFS];
  164. static unsigned long lopec_idedma_regbase;
  165. static void
  166. lopec_ide_probe(void)
  167. {
  168. struct pci_dev *dev = pci_get_device(PCI_VENDOR_ID_WINBOND,
  169. PCI_DEVICE_ID_WINBOND_82C105,
  170. NULL);
  171. lopec_ide_ports_known = 1;
  172. if (dev) {
  173. lopec_ide_regbase[0] = dev->resource[0].start;
  174. lopec_ide_regbase[1] = dev->resource[2].start;
  175. lopec_ide_ctl_regbase[0] = dev->resource[1].start;
  176. lopec_ide_ctl_regbase[1] = dev->resource[3].start;
  177. lopec_idedma_regbase = dev->resource[4].start;
  178. pci_dev_put(dev);
  179. }
  180. }
  181. static int
  182. lopec_ide_default_irq(unsigned long base)
  183. {
  184. if (lopec_ide_ports_known == 0)
  185. lopec_ide_probe();
  186. if (base == lopec_ide_regbase[0])
  187. return 14;
  188. else if (base == lopec_ide_regbase[1])
  189. return 15;
  190. else
  191. return 0;
  192. }
  193. static unsigned long
  194. lopec_ide_default_io_base(int index)
  195. {
  196. if (lopec_ide_ports_known == 0)
  197. lopec_ide_probe();
  198. return lopec_ide_regbase[index];
  199. }
  200. static void __init
  201. lopec_ide_init_hwif_ports(hw_regs_t *hw, unsigned long data,
  202. unsigned long ctl, int *irq)
  203. {
  204. unsigned long reg = data;
  205. uint alt_status_base;
  206. int i;
  207. for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++)
  208. hw->io_ports[i] = reg++;
  209. if (data == lopec_ide_regbase[0]) {
  210. alt_status_base = lopec_ide_ctl_regbase[0] + 2;
  211. hw->irq = 14;
  212. } else if (data == lopec_ide_regbase[1]) {
  213. alt_status_base = lopec_ide_ctl_regbase[1] + 2;
  214. hw->irq = 15;
  215. } else {
  216. alt_status_base = 0;
  217. hw->irq = 0;
  218. }
  219. if (ctl)
  220. hw->io_ports[IDE_CONTROL_OFFSET] = ctl;
  221. else
  222. hw->io_ports[IDE_CONTROL_OFFSET] = alt_status_base;
  223. if (irq != NULL)
  224. *irq = hw->irq;
  225. }
  226. #endif /* BLK_DEV_IDE */
  227. static void __init
  228. lopec_init_IRQ(void)
  229. {
  230. int i;
  231. /*
  232. * Provide the open_pic code with the correct table of interrupts.
  233. */
  234. OpenPIC_InitSenses = lopec_openpic_initsenses;
  235. OpenPIC_NumInitSenses = sizeof(lopec_openpic_initsenses);
  236. mpc10x_set_openpic();
  237. /* We have a cascade on OpenPIC IRQ 0, Linux IRQ 16 */
  238. openpic_hookup_cascade(NUM_8259_INTERRUPTS, "82c59 cascade",
  239. &i8259_irq);
  240. /* Map i8259 interrupts */
  241. for(i = 0; i < NUM_8259_INTERRUPTS; i++)
  242. irq_desc[i].handler = &i8259_pic;
  243. /*
  244. * The EPIC allows for a read in the range of 0xFEF00000 ->
  245. * 0xFEFFFFFF to generate a PCI interrupt-acknowledge transaction.
  246. */
  247. i8259_init(0xfef00000);
  248. }
  249. static int __init
  250. lopec_request_io(void)
  251. {
  252. outb(0x00, 0x4d0);
  253. outb(0xc0, 0x4d1);
  254. request_region(0x00, 0x20, "dma1");
  255. request_region(0x20, 0x20, "pic1");
  256. request_region(0x40, 0x20, "timer");
  257. request_region(0x80, 0x10, "dma page reg");
  258. request_region(0xa0, 0x20, "pic2");
  259. request_region(0xc0, 0x20, "dma2");
  260. return 0;
  261. }
  262. device_initcall(lopec_request_io);
  263. static void __init
  264. lopec_map_io(void)
  265. {
  266. io_block_mapping(0xf0000000, 0xf0000000, 0x10000000, _PAGE_IO);
  267. io_block_mapping(0xb0000000, 0xb0000000, 0x10000000, _PAGE_IO);
  268. }
  269. /*
  270. * Set BAT 3 to map 0xf8000000 to end of physical memory space 1-to-1.
  271. */
  272. static __inline__ void
  273. lopec_set_bat(void)
  274. {
  275. mb();
  276. mtspr(SPRN_DBAT1U, 0xf8000ffe);
  277. mtspr(SPRN_DBAT1L, 0xf800002a);
  278. mb();
  279. }
  280. TODC_ALLOC();
  281. static void __init
  282. lopec_setup_arch(void)
  283. {
  284. TODC_INIT(TODC_TYPE_MK48T37, 0, 0,
  285. ioremap(0xffe80000, 0x8000), 8);
  286. loops_per_jiffy = 100000000/HZ;
  287. lopec_find_bridges();
  288. #ifdef CONFIG_BLK_DEV_INITRD
  289. if (initrd_start)
  290. ROOT_DEV = Root_RAM0;
  291. else
  292. #elif defined(CONFIG_ROOT_NFS)
  293. ROOT_DEV = Root_NFS;
  294. #elif defined(CONFIG_BLK_DEV_IDEDISK)
  295. ROOT_DEV = Root_HDA1;
  296. #else
  297. ROOT_DEV = Root_SDA1;
  298. #endif
  299. #ifdef CONFIG_PPCBUG_NVRAM
  300. /* Read in NVRAM data */
  301. init_prep_nvram();
  302. /* if no bootargs, look in NVRAM */
  303. if ( cmd_line[0] == '\0' ) {
  304. char *bootargs;
  305. bootargs = prep_nvram_get_var("bootargs");
  306. if (bootargs != NULL) {
  307. strcpy(cmd_line, bootargs);
  308. /* again.. */
  309. strcpy(saved_command_line, cmd_line);
  310. }
  311. }
  312. #endif
  313. }
  314. void __init
  315. platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
  316. unsigned long r6, unsigned long r7)
  317. {
  318. parse_bootinfo(find_bootinfo());
  319. lopec_set_bat();
  320. isa_io_base = MPC10X_MAPB_ISA_IO_BASE;
  321. isa_mem_base = MPC10X_MAPB_ISA_MEM_BASE;
  322. pci_dram_offset = MPC10X_MAPB_DRAM_OFFSET;
  323. ISA_DMA_THRESHOLD = 0x00ffffff;
  324. DMA_MODE_READ = 0x44;
  325. DMA_MODE_WRITE = 0x48;
  326. ppc_md.setup_arch = lopec_setup_arch;
  327. ppc_md.show_cpuinfo = lopec_show_cpuinfo;
  328. ppc_md.irq_canonicalize = lopec_irq_canonicalize;
  329. ppc_md.init_IRQ = lopec_init_IRQ;
  330. ppc_md.get_irq = openpic_get_irq;
  331. ppc_md.restart = lopec_restart;
  332. ppc_md.power_off = lopec_power_off;
  333. ppc_md.halt = lopec_halt;
  334. ppc_md.setup_io_mappings = lopec_map_io;
  335. ppc_md.time_init = todc_time_init;
  336. ppc_md.set_rtc_time = todc_set_rtc_time;
  337. ppc_md.get_rtc_time = todc_get_rtc_time;
  338. ppc_md.calibrate_decr = todc_calibrate_decr;
  339. ppc_md.nvram_read_val = todc_direct_read_val;
  340. ppc_md.nvram_write_val = todc_direct_write_val;
  341. #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
  342. ppc_ide_md.default_irq = lopec_ide_default_irq;
  343. ppc_ide_md.default_io_base = lopec_ide_default_io_base;
  344. ppc_ide_md.ide_init_hwif = lopec_ide_init_hwif_ports;
  345. #endif
  346. #ifdef CONFIG_SERIAL_TEXT_DEBUG
  347. ppc_md.progress = gen550_progress;
  348. #endif
  349. }