mpc834x_sys.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. /*
  2. * MPC834x SYS board specific routines
  3. *
  4. * Maintainer: Kumar Gala <galak@kernel.crashing.org>
  5. *
  6. * Copyright 2005 Freescale Semiconductor Inc.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. */
  13. #include <linux/stddef.h>
  14. #include <linux/kernel.h>
  15. #include <linux/init.h>
  16. #include <linux/errno.h>
  17. #include <linux/reboot.h>
  18. #include <linux/pci.h>
  19. #include <linux/kdev_t.h>
  20. #include <linux/major.h>
  21. #include <linux/console.h>
  22. #include <linux/delay.h>
  23. #include <linux/seq_file.h>
  24. #include <linux/root_dev.h>
  25. #include <linux/serial.h>
  26. #include <linux/tty.h> /* for linux/serial_core.h */
  27. #include <linux/serial_core.h>
  28. #include <linux/initrd.h>
  29. #include <linux/module.h>
  30. #include <linux/fsl_devices.h>
  31. #include <asm/system.h>
  32. #include <asm/pgtable.h>
  33. #include <asm/page.h>
  34. #include <asm/atomic.h>
  35. #include <asm/time.h>
  36. #include <asm/io.h>
  37. #include <asm/machdep.h>
  38. #include <asm/ipic.h>
  39. #include <asm/bootinfo.h>
  40. #include <asm/pci-bridge.h>
  41. #include <asm/mpc83xx.h>
  42. #include <asm/irq.h>
  43. #include <asm/kgdb.h>
  44. #include <asm/ppc_sys.h>
  45. #include <mm/mmu_decl.h>
  46. #include <syslib/ppc83xx_setup.h>
  47. #ifndef CONFIG_PCI
  48. unsigned long isa_io_base = 0;
  49. unsigned long isa_mem_base = 0;
  50. #endif
  51. extern unsigned long total_memory; /* in mm/init */
  52. unsigned char __res[sizeof (bd_t)];
  53. #ifdef CONFIG_PCI
  54. int
  55. mpc83xx_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
  56. {
  57. static char pci_irq_table[][4] =
  58. /*
  59. * PCI IDSEL/INTPIN->INTLINE
  60. * A B C D
  61. */
  62. {
  63. {PIRQA, PIRQB, PIRQC, PIRQD}, /* idsel 0x11 */
  64. {PIRQC, PIRQD, PIRQA, PIRQB}, /* idsel 0x12 */
  65. {PIRQD, PIRQA, PIRQB, PIRQC}, /* idsel 0x13 */
  66. {0, 0, 0, 0},
  67. {PIRQA, PIRQB, PIRQC, PIRQD}, /* idsel 0x15 */
  68. {PIRQD, PIRQA, PIRQB, PIRQC}, /* idsel 0x16 */
  69. {PIRQC, PIRQD, PIRQA, PIRQB}, /* idsel 0x17 */
  70. {PIRQB, PIRQC, PIRQD, PIRQA}, /* idsel 0x18 */
  71. {0, 0, 0, 0}, /* idsel 0x19 */
  72. {0, 0, 0, 0}, /* idsel 0x20 */
  73. };
  74. const long min_idsel = 0x11, max_idsel = 0x20, irqs_per_slot = 4;
  75. return PCI_IRQ_TABLE_LOOKUP;
  76. }
  77. int
  78. mpc83xx_exclude_device(u_char bus, u_char devfn)
  79. {
  80. return PCIBIOS_SUCCESSFUL;
  81. }
  82. #endif /* CONFIG_PCI */
  83. /* ************************************************************************
  84. *
  85. * Setup the architecture
  86. *
  87. */
  88. static void __init
  89. mpc834x_sys_setup_arch(void)
  90. {
  91. bd_t *binfo = (bd_t *) __res;
  92. unsigned int freq;
  93. struct gianfar_platform_data *pdata;
  94. struct gianfar_mdio_data *mdata;
  95. /* get the core frequency */
  96. freq = binfo->bi_intfreq;
  97. /* Set loops_per_jiffy to a half-way reasonable value,
  98. for use until calibrate_delay gets called. */
  99. loops_per_jiffy = freq / HZ;
  100. #ifdef CONFIG_PCI
  101. /* setup PCI host bridges */
  102. mpc83xx_setup_hose();
  103. #endif
  104. mpc83xx_early_serial_map();
  105. /* setup the board related info for the MDIO bus */
  106. mdata = (struct gianfar_mdio_data *) ppc_sys_get_pdata(MPC83xx_MDIO);
  107. mdata->irq[0] = MPC83xx_IRQ_EXT1;
  108. mdata->irq[1] = MPC83xx_IRQ_EXT2;
  109. mdata->irq[2] = -1;
  110. mdata->irq[31] = -1;
  111. /* setup the board related information for the enet controllers */
  112. pdata = (struct gianfar_platform_data *) ppc_sys_get_pdata(MPC83xx_TSEC1);
  113. if (pdata) {
  114. pdata->board_flags = FSL_GIANFAR_BRD_HAS_PHY_INTR;
  115. pdata->bus_id = 0;
  116. pdata->phy_id = 0;
  117. memcpy(pdata->mac_addr, binfo->bi_enetaddr, 6);
  118. }
  119. pdata = (struct gianfar_platform_data *) ppc_sys_get_pdata(MPC83xx_TSEC2);
  120. if (pdata) {
  121. pdata->board_flags = FSL_GIANFAR_BRD_HAS_PHY_INTR;
  122. pdata->bus_id = 0;
  123. pdata->phy_id = 1;
  124. memcpy(pdata->mac_addr, binfo->bi_enet1addr, 6);
  125. }
  126. #ifdef CONFIG_BLK_DEV_INITRD
  127. if (initrd_start)
  128. ROOT_DEV = Root_RAM0;
  129. else
  130. #endif
  131. #ifdef CONFIG_ROOT_NFS
  132. ROOT_DEV = Root_NFS;
  133. #else
  134. ROOT_DEV = Root_HDA1;
  135. #endif
  136. }
  137. static void __init
  138. mpc834x_sys_map_io(void)
  139. {
  140. /* we steal the lowest ioremap addr for virt space */
  141. io_block_mapping(VIRT_IMMRBAR, immrbar, 1024*1024, _PAGE_IO);
  142. }
  143. int
  144. mpc834x_sys_show_cpuinfo(struct seq_file *m)
  145. {
  146. uint pvid, svid, phid1;
  147. bd_t *binfo = (bd_t *) __res;
  148. unsigned int freq;
  149. /* get the core frequency */
  150. freq = binfo->bi_intfreq;
  151. pvid = mfspr(SPRN_PVR);
  152. svid = mfspr(SPRN_SVR);
  153. seq_printf(m, "Vendor\t\t: Freescale Inc.\n");
  154. seq_printf(m, "Machine\t\t: mpc%s sys\n", cur_ppc_sys_spec->ppc_sys_name);
  155. seq_printf(m, "core clock\t: %d MHz\n"
  156. "bus clock\t: %d MHz\n",
  157. (int)(binfo->bi_intfreq / 1000000),
  158. (int)(binfo->bi_busfreq / 1000000));
  159. seq_printf(m, "PVR\t\t: 0x%x\n", pvid);
  160. seq_printf(m, "SVR\t\t: 0x%x\n", svid);
  161. /* Display cpu Pll setting */
  162. phid1 = mfspr(SPRN_HID1);
  163. seq_printf(m, "PLL setting\t: 0x%x\n", ((phid1 >> 24) & 0x3f));
  164. /* Display the amount of memory */
  165. seq_printf(m, "Memory\t\t: %d MB\n", (int)(binfo->bi_memsize / (1024 * 1024)));
  166. return 0;
  167. }
  168. void __init
  169. mpc834x_sys_init_IRQ(void)
  170. {
  171. bd_t *binfo = (bd_t *) __res;
  172. u8 senses[8] = {
  173. 0, /* EXT 0 */
  174. IRQ_SENSE_LEVEL, /* EXT 1 */
  175. IRQ_SENSE_LEVEL, /* EXT 2 */
  176. 0, /* EXT 3 */
  177. #ifdef CONFIG_PCI
  178. IRQ_SENSE_LEVEL, /* EXT 4 */
  179. IRQ_SENSE_LEVEL, /* EXT 5 */
  180. IRQ_SENSE_LEVEL, /* EXT 6 */
  181. IRQ_SENSE_LEVEL, /* EXT 7 */
  182. #else
  183. 0, /* EXT 4 */
  184. 0, /* EXT 5 */
  185. 0, /* EXT 6 */
  186. 0, /* EXT 7 */
  187. #endif
  188. };
  189. ipic_init(binfo->bi_immr_base + 0x00700, 0, MPC83xx_IPIC_IRQ_OFFSET, senses, 8);
  190. /* Initialize the default interrupt mapping priorities,
  191. * in case the boot rom changed something on us.
  192. */
  193. ipic_set_default_priority();
  194. }
  195. #if defined(CONFIG_I2C_MPC) && defined(CONFIG_SENSORS_DS1374)
  196. extern ulong ds1374_get_rtc_time(void);
  197. extern int ds1374_set_rtc_time(ulong);
  198. static int __init
  199. mpc834x_rtc_hookup(void)
  200. {
  201. struct timespec tv;
  202. ppc_md.get_rtc_time = ds1374_get_rtc_time;
  203. ppc_md.set_rtc_time = ds1374_set_rtc_time;
  204. tv.tv_nsec = 0;
  205. tv.tv_sec = (ppc_md.get_rtc_time)();
  206. do_settimeofday(&tv);
  207. return 0;
  208. }
  209. late_initcall(mpc834x_rtc_hookup);
  210. #endif
  211. static __inline__ void
  212. mpc834x_sys_set_bat(void)
  213. {
  214. /* we steal the lowest ioremap addr for virt space */
  215. mb();
  216. mtspr(SPRN_DBAT1U, VIRT_IMMRBAR | 0x1e);
  217. mtspr(SPRN_DBAT1L, immrbar | 0x2a);
  218. mb();
  219. }
  220. void __init
  221. platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
  222. unsigned long r6, unsigned long r7)
  223. {
  224. bd_t *binfo = (bd_t *) __res;
  225. /* parse_bootinfo must always be called first */
  226. parse_bootinfo(find_bootinfo());
  227. /*
  228. * If we were passed in a board information, copy it into the
  229. * residual data area.
  230. */
  231. if (r3) {
  232. memcpy((void *) __res, (void *) (r3 + KERNELBASE),
  233. sizeof (bd_t));
  234. }
  235. #if defined(CONFIG_BLK_DEV_INITRD)
  236. /*
  237. * If the init RAM disk has been configured in, and there's a valid
  238. * starting address for it, set it up.
  239. */
  240. if (r4) {
  241. initrd_start = r4 + KERNELBASE;
  242. initrd_end = r5 + KERNELBASE;
  243. }
  244. #endif /* CONFIG_BLK_DEV_INITRD */
  245. /* Copy the kernel command line arguments to a safe place. */
  246. if (r6) {
  247. *(char *) (r7 + KERNELBASE) = 0;
  248. strcpy(cmd_line, (char *) (r6 + KERNELBASE));
  249. }
  250. immrbar = binfo->bi_immr_base;
  251. mpc834x_sys_set_bat();
  252. #if defined(CONFIG_SERIAL_8250) && defined(CONFIG_SERIAL_TEXT_DEBUG)
  253. {
  254. struct uart_port p;
  255. memset(&p, 0, sizeof (p));
  256. p.iotype = UPIO_MEM;
  257. p.membase = (unsigned char __iomem *)(VIRT_IMMRBAR + 0x4500);
  258. p.uartclk = binfo->bi_busfreq;
  259. gen550_init(0, &p);
  260. memset(&p, 0, sizeof (p));
  261. p.iotype = UPIO_MEM;
  262. p.membase = (unsigned char __iomem *)(VIRT_IMMRBAR + 0x4600);
  263. p.uartclk = binfo->bi_busfreq;
  264. gen550_init(1, &p);
  265. }
  266. #endif
  267. identify_ppc_sys_by_id(mfspr(SPRN_SVR));
  268. /* setup the PowerPC module struct */
  269. ppc_md.setup_arch = mpc834x_sys_setup_arch;
  270. ppc_md.show_cpuinfo = mpc834x_sys_show_cpuinfo;
  271. ppc_md.init_IRQ = mpc834x_sys_init_IRQ;
  272. ppc_md.get_irq = ipic_get_irq;
  273. ppc_md.restart = mpc83xx_restart;
  274. ppc_md.power_off = mpc83xx_power_off;
  275. ppc_md.halt = mpc83xx_halt;
  276. ppc_md.find_end_of_memory = mpc83xx_find_end_of_memory;
  277. ppc_md.setup_io_mappings = mpc834x_sys_map_io;
  278. ppc_md.time_init = mpc83xx_time_init;
  279. ppc_md.set_rtc_time = NULL;
  280. ppc_md.get_rtc_time = NULL;
  281. ppc_md.calibrate_decr = mpc83xx_calibrate_decr;
  282. ppc_md.early_serial_map = mpc83xx_early_serial_map;
  283. #if defined(CONFIG_SERIAL_8250) && defined(CONFIG_SERIAL_TEXT_DEBUG)
  284. ppc_md.progress = gen550_progress;
  285. #endif /* CONFIG_SERIAL_8250 && CONFIG_SERIAL_TEXT_DEBUG */
  286. if (ppc_md.progress)
  287. ppc_md.progress("mpc834x_sys_init(): exit", 0);
  288. return;
  289. }