lopec.c 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  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 void
  130. lopec_restart(char *cmd)
  131. {
  132. #define LOPEC_SYSSTAT1 0xffe00000
  133. /* force a hard reset, if possible */
  134. unsigned char reg = *((unsigned char *) LOPEC_SYSSTAT1);
  135. reg |= 0x80;
  136. *((unsigned char *) LOPEC_SYSSTAT1) = reg;
  137. local_irq_disable();
  138. while(1);
  139. #undef LOPEC_SYSSTAT1
  140. }
  141. static void
  142. lopec_halt(void)
  143. {
  144. local_irq_disable();
  145. while(1);
  146. }
  147. static void
  148. lopec_power_off(void)
  149. {
  150. lopec_halt();
  151. }
  152. #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
  153. int lopec_ide_ports_known = 0;
  154. static unsigned long lopec_ide_regbase[MAX_HWIFS];
  155. static unsigned long lopec_ide_ctl_regbase[MAX_HWIFS];
  156. static unsigned long lopec_idedma_regbase;
  157. static void
  158. lopec_ide_probe(void)
  159. {
  160. struct pci_dev *dev = pci_get_device(PCI_VENDOR_ID_WINBOND,
  161. PCI_DEVICE_ID_WINBOND_82C105,
  162. NULL);
  163. lopec_ide_ports_known = 1;
  164. if (dev) {
  165. lopec_ide_regbase[0] = dev->resource[0].start;
  166. lopec_ide_regbase[1] = dev->resource[2].start;
  167. lopec_ide_ctl_regbase[0] = dev->resource[1].start;
  168. lopec_ide_ctl_regbase[1] = dev->resource[3].start;
  169. lopec_idedma_regbase = dev->resource[4].start;
  170. pci_dev_put(dev);
  171. }
  172. }
  173. static int
  174. lopec_ide_default_irq(unsigned long base)
  175. {
  176. if (lopec_ide_ports_known == 0)
  177. lopec_ide_probe();
  178. if (base == lopec_ide_regbase[0])
  179. return 14;
  180. else if (base == lopec_ide_regbase[1])
  181. return 15;
  182. else
  183. return 0;
  184. }
  185. static unsigned long
  186. lopec_ide_default_io_base(int index)
  187. {
  188. if (lopec_ide_ports_known == 0)
  189. lopec_ide_probe();
  190. return lopec_ide_regbase[index];
  191. }
  192. static void __init
  193. lopec_ide_init_hwif_ports(hw_regs_t *hw, unsigned long data,
  194. unsigned long ctl, int *irq)
  195. {
  196. unsigned long reg = data;
  197. uint alt_status_base;
  198. int i;
  199. for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++)
  200. hw->io_ports[i] = reg++;
  201. if (data == lopec_ide_regbase[0]) {
  202. alt_status_base = lopec_ide_ctl_regbase[0] + 2;
  203. hw->irq = 14;
  204. } else if (data == lopec_ide_regbase[1]) {
  205. alt_status_base = lopec_ide_ctl_regbase[1] + 2;
  206. hw->irq = 15;
  207. } else {
  208. alt_status_base = 0;
  209. hw->irq = 0;
  210. }
  211. if (ctl)
  212. hw->io_ports[IDE_CONTROL_OFFSET] = ctl;
  213. else
  214. hw->io_ports[IDE_CONTROL_OFFSET] = alt_status_base;
  215. if (irq != NULL)
  216. *irq = hw->irq;
  217. }
  218. #endif /* BLK_DEV_IDE */
  219. static void __init
  220. lopec_init_IRQ(void)
  221. {
  222. int i;
  223. /*
  224. * Provide the open_pic code with the correct table of interrupts.
  225. */
  226. OpenPIC_InitSenses = lopec_openpic_initsenses;
  227. OpenPIC_NumInitSenses = sizeof(lopec_openpic_initsenses);
  228. mpc10x_set_openpic();
  229. /* We have a cascade on OpenPIC IRQ 0, Linux IRQ 16 */
  230. openpic_hookup_cascade(NUM_8259_INTERRUPTS, "82c59 cascade",
  231. &i8259_irq);
  232. /*
  233. * The EPIC allows for a read in the range of 0xFEF00000 ->
  234. * 0xFEFFFFFF to generate a PCI interrupt-acknowledge transaction.
  235. */
  236. i8259_init(0xfef00000, 0);
  237. }
  238. static int __init
  239. lopec_request_io(void)
  240. {
  241. outb(0x00, 0x4d0);
  242. outb(0xc0, 0x4d1);
  243. request_region(0x00, 0x20, "dma1");
  244. request_region(0x20, 0x20, "pic1");
  245. request_region(0x40, 0x20, "timer");
  246. request_region(0x80, 0x10, "dma page reg");
  247. request_region(0xa0, 0x20, "pic2");
  248. request_region(0xc0, 0x20, "dma2");
  249. return 0;
  250. }
  251. device_initcall(lopec_request_io);
  252. static void __init
  253. lopec_map_io(void)
  254. {
  255. io_block_mapping(0xf0000000, 0xf0000000, 0x10000000, _PAGE_IO);
  256. io_block_mapping(0xb0000000, 0xb0000000, 0x10000000, _PAGE_IO);
  257. }
  258. /*
  259. * Set BAT 3 to map 0xf8000000 to end of physical memory space 1-to-1.
  260. */
  261. static __inline__ void
  262. lopec_set_bat(void)
  263. {
  264. mb();
  265. mtspr(SPRN_DBAT1U, 0xf8000ffe);
  266. mtspr(SPRN_DBAT1L, 0xf800002a);
  267. mb();
  268. }
  269. TODC_ALLOC();
  270. static void __init
  271. lopec_setup_arch(void)
  272. {
  273. TODC_INIT(TODC_TYPE_MK48T37, 0, 0,
  274. ioremap(0xffe80000, 0x8000), 8);
  275. loops_per_jiffy = 100000000/HZ;
  276. lopec_find_bridges();
  277. #ifdef CONFIG_BLK_DEV_INITRD
  278. if (initrd_start)
  279. ROOT_DEV = Root_RAM0;
  280. else
  281. #elif defined(CONFIG_ROOT_NFS)
  282. ROOT_DEV = Root_NFS;
  283. #elif defined(CONFIG_BLK_DEV_IDEDISK)
  284. ROOT_DEV = Root_HDA1;
  285. #else
  286. ROOT_DEV = Root_SDA1;
  287. #endif
  288. #ifdef CONFIG_PPCBUG_NVRAM
  289. /* Read in NVRAM data */
  290. init_prep_nvram();
  291. /* if no bootargs, look in NVRAM */
  292. if ( cmd_line[0] == '\0' ) {
  293. char *bootargs;
  294. bootargs = prep_nvram_get_var("bootargs");
  295. if (bootargs != NULL) {
  296. strcpy(cmd_line, bootargs);
  297. /* again.. */
  298. strcpy(saved_command_line, cmd_line);
  299. }
  300. }
  301. #endif
  302. }
  303. void __init
  304. platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
  305. unsigned long r6, unsigned long r7)
  306. {
  307. parse_bootinfo(find_bootinfo());
  308. lopec_set_bat();
  309. isa_io_base = MPC10X_MAPB_ISA_IO_BASE;
  310. isa_mem_base = MPC10X_MAPB_ISA_MEM_BASE;
  311. pci_dram_offset = MPC10X_MAPB_DRAM_OFFSET;
  312. ISA_DMA_THRESHOLD = 0x00ffffff;
  313. DMA_MODE_READ = 0x44;
  314. DMA_MODE_WRITE = 0x48;
  315. ppc_do_canonicalize_irqs = 1;
  316. ppc_md.setup_arch = lopec_setup_arch;
  317. ppc_md.show_cpuinfo = lopec_show_cpuinfo;
  318. ppc_md.init_IRQ = lopec_init_IRQ;
  319. ppc_md.get_irq = openpic_get_irq;
  320. ppc_md.restart = lopec_restart;
  321. ppc_md.power_off = lopec_power_off;
  322. ppc_md.halt = lopec_halt;
  323. ppc_md.setup_io_mappings = lopec_map_io;
  324. ppc_md.time_init = todc_time_init;
  325. ppc_md.set_rtc_time = todc_set_rtc_time;
  326. ppc_md.get_rtc_time = todc_get_rtc_time;
  327. ppc_md.calibrate_decr = todc_calibrate_decr;
  328. ppc_md.nvram_read_val = todc_direct_read_val;
  329. ppc_md.nvram_write_val = todc_direct_write_val;
  330. #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
  331. ppc_ide_md.default_irq = lopec_ide_default_irq;
  332. ppc_ide_md.default_io_base = lopec_ide_default_io_base;
  333. ppc_ide_md.ide_init_hwif = lopec_ide_init_hwif_ports;
  334. #endif
  335. #ifdef CONFIG_SERIAL_TEXT_DEBUG
  336. ppc_md.progress = gen550_progress;
  337. #endif
  338. }