gef_sbc310.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /*
  2. * GE Fanuc SBC310 board support
  3. *
  4. * Author: Martyn Welch <martyn.welch@gefanuc.com>
  5. *
  6. * Copyright 2008 GE Fanuc Intelligent Platforms Embedded Systems, 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. * Based on: mpc86xx_hpcn.c (MPC86xx HPCN board specific routines)
  14. * Copyright 2006 Freescale Semiconductor Inc.
  15. *
  16. * NEC fixup adapted from arch/mips/pci/fixup-lm2e.c
  17. */
  18. #include <linux/stddef.h>
  19. #include <linux/kernel.h>
  20. #include <linux/pci.h>
  21. #include <linux/kdev_t.h>
  22. #include <linux/delay.h>
  23. #include <linux/seq_file.h>
  24. #include <linux/of_platform.h>
  25. #include <asm/system.h>
  26. #include <asm/time.h>
  27. #include <asm/machdep.h>
  28. #include <asm/pci-bridge.h>
  29. #include <asm/prom.h>
  30. #include <mm/mmu_decl.h>
  31. #include <asm/udbg.h>
  32. #include <asm/mpic.h>
  33. #include <sysdev/fsl_pci.h>
  34. #include <sysdev/fsl_soc.h>
  35. #include "mpc86xx.h"
  36. #include "gef_pic.h"
  37. #undef DEBUG
  38. #ifdef DEBUG
  39. #define DBG (fmt...) do { printk(KERN_ERR "SBC310: " fmt); } while (0)
  40. #else
  41. #define DBG (fmt...) do { } while (0)
  42. #endif
  43. void __iomem *sbc310_regs;
  44. static void __init gef_sbc310_init_irq(void)
  45. {
  46. struct device_node *cascade_node = NULL;
  47. mpc86xx_init_irq();
  48. /*
  49. * There is a simple interrupt handler in the main FPGA, this needs
  50. * to be cascaded into the MPIC
  51. */
  52. cascade_node = of_find_compatible_node(NULL, NULL, "gef,fpga-pic");
  53. if (!cascade_node) {
  54. printk(KERN_WARNING "SBC310: No FPGA PIC\n");
  55. return;
  56. }
  57. gef_pic_init(cascade_node);
  58. of_node_put(cascade_node);
  59. }
  60. static void __init gef_sbc310_setup_arch(void)
  61. {
  62. struct device_node *regs;
  63. #ifdef CONFIG_PCI
  64. struct device_node *np;
  65. for_each_compatible_node(np, "pci", "fsl,mpc8641-pcie") {
  66. fsl_add_bridge(np, 1);
  67. }
  68. #endif
  69. printk(KERN_INFO "GE Fanuc Intelligent Platforms SBC310 6U VPX SBC\n");
  70. #ifdef CONFIG_SMP
  71. mpc86xx_smp_init();
  72. #endif
  73. /* Remap basic board registers */
  74. regs = of_find_compatible_node(NULL, NULL, "gef,fpga-regs");
  75. if (regs) {
  76. sbc310_regs = of_iomap(regs, 0);
  77. if (sbc310_regs == NULL)
  78. printk(KERN_WARNING "Unable to map board registers\n");
  79. of_node_put(regs);
  80. }
  81. }
  82. /* Return the PCB revision */
  83. static unsigned int gef_sbc310_get_board_id(void)
  84. {
  85. unsigned int reg;
  86. reg = ioread32(sbc310_regs);
  87. return reg & 0xff;
  88. }
  89. /* Return the PCB revision */
  90. static unsigned int gef_sbc310_get_pcb_rev(void)
  91. {
  92. unsigned int reg;
  93. reg = ioread32(sbc310_regs);
  94. return (reg >> 8) & 0xff;
  95. }
  96. /* Return the board (software) revision */
  97. static unsigned int gef_sbc310_get_board_rev(void)
  98. {
  99. unsigned int reg;
  100. reg = ioread32(sbc310_regs);
  101. return (reg >> 16) & 0xff;
  102. }
  103. /* Return the FPGA revision */
  104. static unsigned int gef_sbc310_get_fpga_rev(void)
  105. {
  106. unsigned int reg;
  107. reg = ioread32(sbc310_regs);
  108. return (reg >> 24) & 0xf;
  109. }
  110. static void gef_sbc310_show_cpuinfo(struct seq_file *m)
  111. {
  112. uint svid = mfspr(SPRN_SVR);
  113. seq_printf(m, "Vendor\t\t: GE Fanuc Intelligent Platforms\n");
  114. seq_printf(m, "Board ID\t: 0x%2.2x\n", gef_sbc310_get_board_id());
  115. seq_printf(m, "Revision\t: %u%c\n", gef_sbc310_get_pcb_rev(),
  116. ('A' + gef_sbc310_get_board_rev() - 1));
  117. seq_printf(m, "FPGA Revision\t: %u\n", gef_sbc310_get_fpga_rev());
  118. seq_printf(m, "SVR\t\t: 0x%x\n", svid);
  119. }
  120. static void __init gef_sbc310_nec_fixup(struct pci_dev *pdev)
  121. {
  122. unsigned int val;
  123. /* Do not do the fixup on other platforms! */
  124. if (!machine_is(gef_sbc310))
  125. return;
  126. printk(KERN_INFO "Running NEC uPD720101 Fixup\n");
  127. /* Ensure only ports 1 & 2 are enabled */
  128. pci_read_config_dword(pdev, 0xe0, &val);
  129. pci_write_config_dword(pdev, 0xe0, (val & ~7) | 0x2);
  130. /* System clock is 48-MHz Oscillator and EHCI Enabled. */
  131. pci_write_config_dword(pdev, 0xe4, 1 << 5);
  132. }
  133. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NEC, PCI_DEVICE_ID_NEC_USB,
  134. gef_sbc310_nec_fixup);
  135. /*
  136. * Called very early, device-tree isn't unflattened
  137. *
  138. * This function is called to determine whether the BSP is compatible with the
  139. * supplied device-tree, which is assumed to be the correct one for the actual
  140. * board. It is expected thati, in the future, a kernel may support multiple
  141. * boards.
  142. */
  143. static int __init gef_sbc310_probe(void)
  144. {
  145. unsigned long root = of_get_flat_dt_root();
  146. if (of_flat_dt_is_compatible(root, "gef,sbc310"))
  147. return 1;
  148. return 0;
  149. }
  150. static long __init mpc86xx_time_init(void)
  151. {
  152. unsigned int temp;
  153. /* Set the time base to zero */
  154. mtspr(SPRN_TBWL, 0);
  155. mtspr(SPRN_TBWU, 0);
  156. temp = mfspr(SPRN_HID0);
  157. temp |= HID0_TBEN;
  158. mtspr(SPRN_HID0, temp);
  159. asm volatile("isync");
  160. return 0;
  161. }
  162. static __initdata struct of_device_id of_bus_ids[] = {
  163. { .compatible = "simple-bus", },
  164. { .compatible = "gianfar", },
  165. {},
  166. };
  167. static int __init declare_of_platform_devices(void)
  168. {
  169. printk(KERN_DEBUG "Probe platform devices\n");
  170. of_platform_bus_probe(NULL, of_bus_ids, NULL);
  171. return 0;
  172. }
  173. machine_device_initcall(gef_sbc310, declare_of_platform_devices);
  174. define_machine(gef_sbc310) {
  175. .name = "GE Fanuc SBC310",
  176. .probe = gef_sbc310_probe,
  177. .setup_arch = gef_sbc310_setup_arch,
  178. .init_IRQ = gef_sbc310_init_irq,
  179. .show_cpuinfo = gef_sbc310_show_cpuinfo,
  180. .get_irq = mpic_get_irq,
  181. .restart = fsl_rstcr_restart,
  182. .time_init = mpc86xx_time_init,
  183. .calibrate_decr = generic_calibrate_decr,
  184. .progress = udbg_progress,
  185. #ifdef CONFIG_PCI
  186. .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
  187. #endif
  188. };