ppc476.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * PowerPC 476FPE board specific routines
  4. *
  5. * Copyright © 2013 Tony Breeds IBM Corporation
  6. * Copyright © 2013 Alistair Popple IBM Corporation
  7. *
  8. * Based on earlier code:
  9. * Matt Porter <[email protected]>
  10. * Copyright 2002-2005 MontaVista Software Inc.
  11. *
  12. * Eugene Surovegin <[email protected]> or <[email protected]>
  13. * Copyright (c) 2003-2005 Zultys Technologies
  14. *
  15. * Rewritten and ported to the merged powerpc tree:
  16. * Copyright 2007 David Gibson <[email protected]>, IBM Corporation.
  17. * Copyright © 2011 David Kliekamp IBM Corporation
  18. */
  19. #include <linux/init.h>
  20. #include <linux/of.h>
  21. #include <linux/of_address.h>
  22. #include <linux/of_platform.h>
  23. #include <linux/rtc.h>
  24. #include <asm/machdep.h>
  25. #include <asm/udbg.h>
  26. #include <asm/time.h>
  27. #include <asm/uic.h>
  28. #include <asm/ppc4xx.h>
  29. #include <asm/mpic.h>
  30. #include <asm/mmu.h>
  31. #include <asm/swiotlb.h>
  32. #include <linux/pci.h>
  33. #include <linux/i2c.h>
  34. static const struct of_device_id ppc47x_of_bus[] __initconst = {
  35. { .compatible = "ibm,plb4", },
  36. { .compatible = "ibm,plb6", },
  37. { .compatible = "ibm,opb", },
  38. { .compatible = "ibm,ebc", },
  39. {},
  40. };
  41. /* The EEPROM is missing and the default values are bogus. This forces USB in
  42. * to EHCI mode */
  43. static void quirk_ppc_currituck_usb_fixup(struct pci_dev *dev)
  44. {
  45. if (of_machine_is_compatible("ibm,currituck")) {
  46. pci_write_config_dword(dev, 0xe0, 0x0114231f);
  47. pci_write_config_dword(dev, 0xe4, 0x00006c40);
  48. }
  49. }
  50. DECLARE_PCI_FIXUP_HEADER(0x1033, 0x0035, quirk_ppc_currituck_usb_fixup);
  51. /* Akebono has an AVR microcontroller attached to the I2C bus
  52. * which is used to power off/reset the system. */
  53. /* AVR I2C Commands */
  54. #define AVR_PWRCTL_CMD (0x26)
  55. /* Flags for the power control I2C commands */
  56. #define AVR_PWRCTL_PWROFF (0x01)
  57. #define AVR_PWRCTL_RESET (0x02)
  58. static struct i2c_client *avr_i2c_client;
  59. static void __noreturn avr_halt_system(int pwrctl_flags)
  60. {
  61. /* Request the AVR to reset the system */
  62. i2c_smbus_write_byte_data(avr_i2c_client,
  63. AVR_PWRCTL_CMD, pwrctl_flags);
  64. /* Wait for system to be reset */
  65. while (1)
  66. ;
  67. }
  68. static void avr_power_off_system(void)
  69. {
  70. avr_halt_system(AVR_PWRCTL_PWROFF);
  71. }
  72. static void __noreturn avr_reset_system(char *cmd)
  73. {
  74. avr_halt_system(AVR_PWRCTL_RESET);
  75. }
  76. static int avr_probe(struct i2c_client *client)
  77. {
  78. avr_i2c_client = client;
  79. ppc_md.restart = avr_reset_system;
  80. pm_power_off = avr_power_off_system;
  81. return 0;
  82. }
  83. static const struct i2c_device_id avr_id[] = {
  84. { "akebono-avr", 0 },
  85. { }
  86. };
  87. static struct i2c_driver avr_driver = {
  88. .driver = {
  89. .name = "akebono-avr",
  90. },
  91. .probe_new = avr_probe,
  92. .id_table = avr_id,
  93. };
  94. static int __init ppc47x_device_probe(void)
  95. {
  96. i2c_add_driver(&avr_driver);
  97. of_platform_bus_probe(NULL, ppc47x_of_bus, NULL);
  98. return 0;
  99. }
  100. machine_device_initcall(ppc47x, ppc47x_device_probe);
  101. static void __init ppc47x_init_irq(void)
  102. {
  103. struct device_node *np;
  104. /* Find top level interrupt controller */
  105. for_each_node_with_property(np, "interrupt-controller") {
  106. if (of_get_property(np, "interrupts", NULL) == NULL)
  107. break;
  108. }
  109. if (np == NULL)
  110. panic("Can't find top level interrupt controller");
  111. /* Check type and do appropriate initialization */
  112. if (of_device_is_compatible(np, "chrp,open-pic")) {
  113. /* The MPIC driver will get everything it needs from the
  114. * device-tree, just pass 0 to all arguments
  115. */
  116. struct mpic *mpic =
  117. mpic_alloc(np, 0, MPIC_NO_RESET, 0, 0, " MPIC ");
  118. BUG_ON(mpic == NULL);
  119. mpic_init(mpic);
  120. ppc_md.get_irq = mpic_get_irq;
  121. } else
  122. panic("Unrecognized top level interrupt controller");
  123. of_node_put(np);
  124. }
  125. #ifdef CONFIG_SMP
  126. static void smp_ppc47x_setup_cpu(int cpu)
  127. {
  128. mpic_setup_this_cpu();
  129. }
  130. static int smp_ppc47x_kick_cpu(int cpu)
  131. {
  132. struct device_node *cpunode = of_get_cpu_node(cpu, NULL);
  133. const u64 *spin_table_addr_prop;
  134. u32 *spin_table;
  135. extern void start_secondary_47x(void);
  136. BUG_ON(cpunode == NULL);
  137. /* Assume spin table. We could test for the enable-method in
  138. * the device-tree but currently there's little point as it's
  139. * our only supported method
  140. */
  141. spin_table_addr_prop =
  142. of_get_property(cpunode, "cpu-release-addr", NULL);
  143. if (spin_table_addr_prop == NULL) {
  144. pr_err("CPU%d: Can't start, missing cpu-release-addr !\n",
  145. cpu);
  146. return 1;
  147. }
  148. /* Assume it's mapped as part of the linear mapping. This is a bit
  149. * fishy but will work fine for now
  150. *
  151. * XXX: Is there any reason to assume differently?
  152. */
  153. spin_table = (u32 *)__va(*spin_table_addr_prop);
  154. pr_debug("CPU%d: Spin table mapped at %p\n", cpu, spin_table);
  155. spin_table[3] = cpu;
  156. smp_wmb();
  157. spin_table[1] = __pa(start_secondary_47x);
  158. mb();
  159. return 0;
  160. }
  161. static struct smp_ops_t ppc47x_smp_ops = {
  162. .probe = smp_mpic_probe,
  163. .message_pass = smp_mpic_message_pass,
  164. .setup_cpu = smp_ppc47x_setup_cpu,
  165. .kick_cpu = smp_ppc47x_kick_cpu,
  166. .give_timebase = smp_generic_give_timebase,
  167. .take_timebase = smp_generic_take_timebase,
  168. };
  169. static void __init ppc47x_smp_init(void)
  170. {
  171. if (mmu_has_feature(MMU_FTR_TYPE_47x))
  172. smp_ops = &ppc47x_smp_ops;
  173. }
  174. #else /* CONFIG_SMP */
  175. static void __init ppc47x_smp_init(void) { }
  176. #endif /* CONFIG_SMP */
  177. static void __init ppc47x_setup_arch(void)
  178. {
  179. /* No need to check the DMA config as we /know/ our windows are all of
  180. * RAM. Lets hope that doesn't change */
  181. swiotlb_detect_4g();
  182. ppc47x_smp_init();
  183. }
  184. static int board_rev = -1;
  185. static int __init ppc47x_get_board_rev(void)
  186. {
  187. int reg;
  188. u8 __iomem *fpga;
  189. struct device_node *np = NULL;
  190. if (of_machine_is_compatible("ibm,currituck")) {
  191. np = of_find_compatible_node(NULL, NULL, "ibm,currituck-fpga");
  192. reg = 0;
  193. } else if (of_machine_is_compatible("ibm,akebono")) {
  194. np = of_find_compatible_node(NULL, NULL, "ibm,akebono-fpga");
  195. reg = 2;
  196. }
  197. if (!np)
  198. goto fail;
  199. fpga = of_iomap(np, 0);
  200. of_node_put(np);
  201. if (!fpga)
  202. goto fail;
  203. board_rev = ioread8(fpga + reg) & 0x03;
  204. pr_info("%s: Found board revision %d\n", __func__, board_rev);
  205. iounmap(fpga);
  206. return 0;
  207. fail:
  208. pr_info("%s: Unable to find board revision\n", __func__);
  209. return 0;
  210. }
  211. machine_arch_initcall(ppc47x, ppc47x_get_board_rev);
  212. /* Use USB controller should have been hardware swizzled but it wasn't :( */
  213. static void ppc47x_pci_irq_fixup(struct pci_dev *dev)
  214. {
  215. if (dev->vendor == 0x1033 && (dev->device == 0x0035 ||
  216. dev->device == 0x00e0)) {
  217. if (board_rev == 0) {
  218. dev->irq = irq_create_mapping(NULL, 47);
  219. pr_info("%s: Mapping irq %d\n", __func__, dev->irq);
  220. } else if (board_rev == 2) {
  221. dev->irq = irq_create_mapping(NULL, 49);
  222. pr_info("%s: Mapping irq %d\n", __func__, dev->irq);
  223. } else {
  224. pr_alert("%s: Unknown board revision\n", __func__);
  225. }
  226. }
  227. }
  228. /*
  229. * Called very early, MMU is off, device-tree isn't unflattened
  230. */
  231. static int __init ppc47x_probe(void)
  232. {
  233. if (of_machine_is_compatible("ibm,akebono"))
  234. return 1;
  235. if (of_machine_is_compatible("ibm,currituck")) {
  236. ppc_md.pci_irq_fixup = ppc47x_pci_irq_fixup;
  237. return 1;
  238. }
  239. return 0;
  240. }
  241. define_machine(ppc47x) {
  242. .name = "PowerPC 47x",
  243. .probe = ppc47x_probe,
  244. .progress = udbg_progress,
  245. .init_IRQ = ppc47x_init_irq,
  246. .setup_arch = ppc47x_setup_arch,
  247. .restart = ppc4xx_reset_system,
  248. .calibrate_decr = generic_calibrate_decr,
  249. };