lopec.c 9.6 KB

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