mpc834x_sys.c 8.4 KB

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