lite5200.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Freescale Lite5200 board support
  4. *
  5. * Written by: Grant Likely <[email protected]>
  6. *
  7. * Copyright (C) Secret Lab Technologies Ltd. 2006. All rights reserved.
  8. * Copyright 2006 Freescale Semiconductor, Inc. All rights reserved.
  9. *
  10. * Description:
  11. */
  12. #undef DEBUG
  13. #include <linux/init.h>
  14. #include <linux/pci.h>
  15. #include <linux/of.h>
  16. #include <linux/of_address.h>
  17. #include <linux/root_dev.h>
  18. #include <linux/initrd.h>
  19. #include <asm/time.h>
  20. #include <asm/io.h>
  21. #include <asm/machdep.h>
  22. #include <asm/mpc52xx.h>
  23. /* ************************************************************************
  24. *
  25. * Setup the architecture
  26. *
  27. */
  28. /* mpc5200 device tree match tables */
  29. static const struct of_device_id mpc5200_cdm_ids[] __initconst = {
  30. { .compatible = "fsl,mpc5200-cdm", },
  31. { .compatible = "mpc5200-cdm", },
  32. {}
  33. };
  34. static const struct of_device_id mpc5200_gpio_ids[] __initconst = {
  35. { .compatible = "fsl,mpc5200-gpio", },
  36. { .compatible = "mpc5200-gpio", },
  37. {}
  38. };
  39. /*
  40. * Fix clock configuration.
  41. *
  42. * Firmware is supposed to be responsible for this. If you are creating a
  43. * new board port, do *NOT* duplicate this code. Fix your boot firmware
  44. * to set it correctly in the first place
  45. */
  46. static void __init
  47. lite5200_fix_clock_config(void)
  48. {
  49. struct device_node *np;
  50. struct mpc52xx_cdm __iomem *cdm;
  51. /* Map zones */
  52. np = of_find_matching_node(NULL, mpc5200_cdm_ids);
  53. cdm = of_iomap(np, 0);
  54. of_node_put(np);
  55. if (!cdm) {
  56. printk(KERN_ERR "%s() failed; expect abnormal behaviour\n",
  57. __func__);
  58. return;
  59. }
  60. /* Use internal 48 Mhz */
  61. out_8(&cdm->ext_48mhz_en, 0x00);
  62. out_8(&cdm->fd_enable, 0x01);
  63. if (in_be32(&cdm->rstcfg) & 0x40) /* Assumes 33Mhz clock */
  64. out_be16(&cdm->fd_counters, 0x0001);
  65. else
  66. out_be16(&cdm->fd_counters, 0x5555);
  67. /* Unmap the regs */
  68. iounmap(cdm);
  69. }
  70. /*
  71. * Fix setting of port_config register.
  72. *
  73. * Firmware is supposed to be responsible for this. If you are creating a
  74. * new board port, do *NOT* duplicate this code. Fix your boot firmware
  75. * to set it correctly in the first place
  76. */
  77. static void __init
  78. lite5200_fix_port_config(void)
  79. {
  80. struct device_node *np;
  81. struct mpc52xx_gpio __iomem *gpio;
  82. u32 port_config;
  83. np = of_find_matching_node(NULL, mpc5200_gpio_ids);
  84. gpio = of_iomap(np, 0);
  85. of_node_put(np);
  86. if (!gpio) {
  87. printk(KERN_ERR "%s() failed. expect abnormal behavior\n",
  88. __func__);
  89. return;
  90. }
  91. /* Set port config */
  92. port_config = in_be32(&gpio->port_config);
  93. port_config &= ~0x00800000; /* 48Mhz internal, pin is GPIO */
  94. port_config &= ~0x00007000; /* USB port : Differential mode */
  95. port_config |= 0x00001000; /* USB 1 only */
  96. port_config &= ~0x03000000; /* ATA CS is on csb_4/5 */
  97. port_config |= 0x01000000;
  98. pr_debug("port_config: old:%x new:%x\n",
  99. in_be32(&gpio->port_config), port_config);
  100. out_be32(&gpio->port_config, port_config);
  101. /* Unmap zone */
  102. iounmap(gpio);
  103. }
  104. #ifdef CONFIG_PM
  105. static void lite5200_suspend_prepare(void __iomem *mbar)
  106. {
  107. u8 pin = 1; /* GPIO_WKUP_1 (GPIO_PSC2_4) */
  108. u8 level = 0; /* wakeup on low level */
  109. mpc52xx_set_wakeup_gpio(pin, level);
  110. /*
  111. * power down usb port
  112. * this needs to be called before of-ohci suspend code
  113. */
  114. /* set ports to "power switched" and "powered at the same time"
  115. * USB Rh descriptor A: NPS = 0, PSM = 0 */
  116. out_be32(mbar + 0x1048, in_be32(mbar + 0x1048) & ~0x300);
  117. /* USB Rh status: LPS = 1 - turn off power */
  118. out_be32(mbar + 0x1050, 0x00000001);
  119. }
  120. static void lite5200_resume_finish(void __iomem *mbar)
  121. {
  122. /* USB Rh status: LPSC = 1 - turn on power */
  123. out_be32(mbar + 0x1050, 0x00010000);
  124. }
  125. #endif
  126. static void __init lite5200_setup_arch(void)
  127. {
  128. if (ppc_md.progress)
  129. ppc_md.progress("lite5200_setup_arch()", 0);
  130. /* Map important registers from the internal memory map */
  131. mpc52xx_map_common_devices();
  132. /* Some mpc5200 & mpc5200b related configuration */
  133. mpc5200_setup_xlb_arbiter();
  134. /* Fix things that firmware should have done. */
  135. lite5200_fix_clock_config();
  136. lite5200_fix_port_config();
  137. #ifdef CONFIG_PM
  138. mpc52xx_suspend.board_suspend_prepare = lite5200_suspend_prepare;
  139. mpc52xx_suspend.board_resume_finish = lite5200_resume_finish;
  140. lite5200_pm_init();
  141. #endif
  142. }
  143. static const char * const board[] __initconst = {
  144. "fsl,lite5200",
  145. "fsl,lite5200b",
  146. NULL,
  147. };
  148. /*
  149. * Called very early, MMU is off, device-tree isn't unflattened
  150. */
  151. static int __init lite5200_probe(void)
  152. {
  153. return of_device_compatible_match(of_root, board);
  154. }
  155. define_machine(lite5200) {
  156. .name = "lite5200",
  157. .probe = lite5200_probe,
  158. .setup_arch = lite5200_setup_arch,
  159. .discover_phbs = mpc52xx_setup_pci,
  160. .init = mpc52xx_declare_of_platform_devices,
  161. .init_IRQ = mpc52xx_init_irq,
  162. .get_irq = mpc52xx_get_irq,
  163. .restart = mpc52xx_restart,
  164. .calibrate_decr = generic_calibrate_decr,
  165. };