km82xx.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Keymile km82xx support
  4. * Copyright 2008-2011 DENX Software Engineering GmbH
  5. * Author: Heiko Schocher <[email protected]>
  6. *
  7. * based on code from:
  8. * Copyright 2007 Freescale Semiconductor, Inc.
  9. * Author: Scott Wood <[email protected]>
  10. */
  11. #include <linux/init.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/fsl_devices.h>
  14. #include <linux/of_platform.h>
  15. #include <linux/io.h>
  16. #include <asm/cpm2.h>
  17. #include <asm/udbg.h>
  18. #include <asm/machdep.h>
  19. #include <linux/time.h>
  20. #include <asm/mpc8260.h>
  21. #include <sysdev/fsl_soc.h>
  22. #include <sysdev/cpm2_pic.h>
  23. #include "pq2.h"
  24. static void __init km82xx_pic_init(void)
  25. {
  26. struct device_node *np = of_find_compatible_node(NULL, NULL,
  27. "fsl,pq2-pic");
  28. if (!np) {
  29. pr_err("PIC init: can not find cpm-pic node\n");
  30. return;
  31. }
  32. cpm2_pic_init(np);
  33. of_node_put(np);
  34. }
  35. struct cpm_pin {
  36. int port, pin, flags;
  37. };
  38. static __initdata struct cpm_pin km82xx_pins[] = {
  39. /* SMC1 */
  40. {2, 4, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  41. {2, 5, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
  42. /* SMC2 */
  43. {0, 8, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  44. {0, 9, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
  45. /* SCC1 */
  46. {2, 21, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  47. {2, 15, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  48. {3, 31, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  49. {3, 30, CPM_PIN_OUTPUT | CPM_PIN_SECONDARY},
  50. /* SCC4 */
  51. {2, 25, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  52. {2, 24, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  53. {2, 9, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  54. {2, 8, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  55. {3, 22, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  56. {3, 21, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
  57. /* FCC1 */
  58. {0, 14, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  59. {0, 15, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  60. {0, 16, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  61. {0, 17, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  62. {0, 18, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
  63. {0, 19, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
  64. {0, 20, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
  65. {0, 21, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
  66. {0, 26, CPM_PIN_INPUT | CPM_PIN_SECONDARY},
  67. {0, 27, CPM_PIN_INPUT | CPM_PIN_SECONDARY},
  68. {0, 28, CPM_PIN_OUTPUT | CPM_PIN_SECONDARY},
  69. {0, 29, CPM_PIN_OUTPUT | CPM_PIN_SECONDARY},
  70. {0, 30, CPM_PIN_INPUT | CPM_PIN_SECONDARY},
  71. {0, 31, CPM_PIN_INPUT | CPM_PIN_SECONDARY},
  72. {2, 22, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  73. {2, 23, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  74. /* FCC2 */
  75. {1, 18, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  76. {1, 19, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  77. {1, 20, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  78. {1, 21, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  79. {1, 22, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
  80. {1, 23, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
  81. {1, 24, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
  82. {1, 25, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
  83. {1, 26, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  84. {1, 27, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  85. {1, 28, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  86. {1, 29, CPM_PIN_OUTPUT | CPM_PIN_SECONDARY},
  87. {1, 30, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  88. {1, 31, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
  89. {2, 18, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  90. {2, 19, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
  91. /* MDC */
  92. {0, 13, CPM_PIN_OUTPUT | CPM_PIN_GPIO},
  93. #if defined(CONFIG_I2C_CPM)
  94. /* I2C */
  95. {3, 14, CPM_PIN_INPUT | CPM_PIN_SECONDARY | CPM_PIN_OPENDRAIN},
  96. {3, 15, CPM_PIN_INPUT | CPM_PIN_SECONDARY | CPM_PIN_OPENDRAIN},
  97. #endif
  98. /* USB */
  99. {0, 10, CPM_PIN_OUTPUT | CPM_PIN_GPIO}, /* FULL_SPEED */
  100. {0, 11, CPM_PIN_OUTPUT | CPM_PIN_GPIO}, /*/SLAVE */
  101. {2, 10, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, /* RXN */
  102. {2, 11, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, /* RXP */
  103. {2, 20, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY}, /* /OE */
  104. {2, 27, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, /* RXCLK */
  105. {3, 23, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY}, /* TXP */
  106. {3, 24, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY}, /* TXN */
  107. {3, 25, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, /* RXD */
  108. /* SPI */
  109. {3, 16, CPM_PIN_INPUT | CPM_PIN_SECONDARY},/* SPI_MISO PD16 */
  110. {3, 17, CPM_PIN_INPUT | CPM_PIN_SECONDARY},/* SPI_MOSI PD17 */
  111. {3, 18, CPM_PIN_INPUT | CPM_PIN_SECONDARY},/* SPI_CLK PD18 */
  112. };
  113. static void __init init_ioports(void)
  114. {
  115. int i;
  116. for (i = 0; i < ARRAY_SIZE(km82xx_pins); i++) {
  117. const struct cpm_pin *pin = &km82xx_pins[i];
  118. cpm2_set_pin(pin->port, pin->pin, pin->flags);
  119. }
  120. cpm2_smc_clk_setup(CPM_CLK_SMC2, CPM_BRG8);
  121. cpm2_smc_clk_setup(CPM_CLK_SMC1, CPM_BRG7);
  122. cpm2_clk_setup(CPM_CLK_SCC1, CPM_CLK11, CPM_CLK_RX);
  123. cpm2_clk_setup(CPM_CLK_SCC1, CPM_CLK11, CPM_CLK_TX);
  124. cpm2_clk_setup(CPM_CLK_SCC3, CPM_CLK5, CPM_CLK_RTX);
  125. cpm2_clk_setup(CPM_CLK_SCC4, CPM_CLK7, CPM_CLK_RX);
  126. cpm2_clk_setup(CPM_CLK_SCC4, CPM_CLK8, CPM_CLK_TX);
  127. cpm2_clk_setup(CPM_CLK_FCC1, CPM_CLK10, CPM_CLK_RX);
  128. cpm2_clk_setup(CPM_CLK_FCC1, CPM_CLK9, CPM_CLK_TX);
  129. cpm2_clk_setup(CPM_CLK_FCC2, CPM_CLK13, CPM_CLK_RX);
  130. cpm2_clk_setup(CPM_CLK_FCC2, CPM_CLK14, CPM_CLK_TX);
  131. /* Force USB FULL SPEED bit to '1' */
  132. setbits32(&cpm2_immr->im_ioport.iop_pdata, 1 << (31 - 10));
  133. /* clear USB_SLAVE */
  134. clrbits32(&cpm2_immr->im_ioport.iop_pdata, 1 << (31 - 11));
  135. }
  136. static void __init km82xx_setup_arch(void)
  137. {
  138. if (ppc_md.progress)
  139. ppc_md.progress("km82xx_setup_arch()", 0);
  140. cpm2_reset();
  141. /* When this is set, snooping CPM DMA from RAM causes
  142. * machine checks. See erratum SIU18.
  143. */
  144. clrbits32(&cpm2_immr->im_siu_conf.siu_82xx.sc_bcr, MPC82XX_BCR_PLDP);
  145. init_ioports();
  146. if (ppc_md.progress)
  147. ppc_md.progress("km82xx_setup_arch(), finish", 0);
  148. }
  149. static const struct of_device_id of_bus_ids[] __initconst = {
  150. { .compatible = "simple-bus", },
  151. {},
  152. };
  153. static int __init declare_of_platform_devices(void)
  154. {
  155. of_platform_bus_probe(NULL, of_bus_ids, NULL);
  156. return 0;
  157. }
  158. machine_device_initcall(km82xx, declare_of_platform_devices);
  159. /*
  160. * Called very early, device-tree isn't unflattened
  161. */
  162. static int __init km82xx_probe(void)
  163. {
  164. return of_machine_is_compatible("keymile,km82xx");
  165. }
  166. define_machine(km82xx)
  167. {
  168. .name = "Keymile km82xx",
  169. .probe = km82xx_probe,
  170. .setup_arch = km82xx_setup_arch,
  171. .init_IRQ = km82xx_pic_init,
  172. .get_irq = cpm2_get_irq,
  173. .calibrate_decr = generic_calibrate_decr,
  174. .restart = pq2_restart,
  175. .progress = udbg_progress,
  176. };