lopec.c 9.6 KB

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